Skip to content

Commit 1c24ff6

Browse files
Minor changes
1 parent c609653 commit 1c24ff6

2 files changed

Lines changed: 51 additions & 13 deletions

File tree

AlphaChiTech.Virtualization/PaginationManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ public void OnReset(int count)
932932
this.ProviderAsync.OnReset(count);
933933
}
934934

935-
RaiseCountChanged(true, count);
935+
if(count >= -1)
936+
RaiseCountChanged(true, count);
936937

937938
}
938939

AlphaChiTech.Virtualization/VirtualizingObservableCollection.cs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.ComponentModel;
66
using System.Linq;
77
using System.Text;
8+
using System.Threading;
89
using System.Threading.Tasks;
910

1011
namespace AlphaChiTech.Virtualization
@@ -698,44 +699,80 @@ void InternalClear()
698699
}
699700
}
700701

702+
CancellationTokenSource _ResetToken = null;
703+
701704
public async void ResetAsync()
702705
{
703-
if(this.Provider != null)
706+
CancellationTokenSource cts = null;
707+
708+
lock(this)
709+
{
710+
if(_ResetToken != null)
711+
{
712+
_ResetToken.Cancel();
713+
_ResetToken = null;
714+
}
715+
716+
cts = _ResetToken = new CancellationTokenSource();
717+
}
718+
719+
if (this.Provider != null)
704720
{
705721
if (this.Provider is IProviderPreReset)
706722
{
707723
(this.Provider as IProviderPreReset).OnBeforeReset();
724+
if (cts.IsCancellationRequested)
725+
{
726+
return;
727+
}
728+
708729
}
709-
this.Provider.OnReset(-1);
710730

711-
Task.Run( async () =>
731+
//this.Provider.OnReset(-2);
732+
733+
Task.Run(async () =>
712734
{
713735
if (this.Provider is IAsyncResetProvider)
714736
{
715737
int count = await (this.Provider as IAsyncResetProvider).GetCountAsync();
716-
VirtualizationManager.Instance.RunOnUI(() =>
717-
this.Provider.OnReset(count)
718-
);
738+
if (!cts.IsCancellationRequested)
739+
{
740+
VirtualizationManager.Instance.RunOnUI(() =>
741+
this.Provider.OnReset(count)
742+
);
743+
}
719744

720745
}
721746
else
722747
{
723748
int count = this.Provider.GetCount(false);
724-
VirtualizationManager.Instance.RunOnUI(() =>
725-
this.Provider.OnReset(count)
726-
);
749+
if (!cts.IsCancellationRequested)
750+
{
751+
VirtualizationManager.Instance.RunOnUI(() =>
752+
this.Provider.OnReset(count)
753+
);
754+
}
727755
}
756+
728757
});
729-
730-
}
731-
else
758+
759+
}
760+
else
732761
{
733762
if (this.ProviderAsync is IProviderPreReset)
734763
{
735764
(this.ProviderAsync as IProviderPreReset).OnBeforeReset();
736765
}
737766
this.ProviderAsync.OnReset(await this.ProviderAsync.Count);
738767
}
768+
769+
lock(this)
770+
{
771+
if(_ResetToken == cts)
772+
{
773+
_ResetToken = null;
774+
}
775+
}
739776
}
740777

741778
T InternalGetValue(int index, string selectionContext)

0 commit comments

Comments
 (0)