|
5 | 5 | using System.ComponentModel; |
6 | 6 | using System.Linq; |
7 | 7 | using System.Text; |
| 8 | +using System.Threading; |
8 | 9 | using System.Threading.Tasks; |
9 | 10 |
|
10 | 11 | namespace AlphaChiTech.Virtualization |
@@ -698,44 +699,80 @@ void InternalClear() |
698 | 699 | } |
699 | 700 | } |
700 | 701 |
|
| 702 | + CancellationTokenSource _ResetToken = null; |
| 703 | + |
701 | 704 | public async void ResetAsync() |
702 | 705 | { |
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) |
704 | 720 | { |
705 | 721 | if (this.Provider is IProviderPreReset) |
706 | 722 | { |
707 | 723 | (this.Provider as IProviderPreReset).OnBeforeReset(); |
| 724 | + if (cts.IsCancellationRequested) |
| 725 | + { |
| 726 | + return; |
| 727 | + } |
| 728 | + |
708 | 729 | } |
709 | | - this.Provider.OnReset(-1); |
710 | 730 |
|
711 | | - Task.Run( async () => |
| 731 | + //this.Provider.OnReset(-2); |
| 732 | + |
| 733 | + Task.Run(async () => |
712 | 734 | { |
713 | 735 | if (this.Provider is IAsyncResetProvider) |
714 | 736 | { |
715 | 737 | 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 | + } |
719 | 744 |
|
720 | 745 | } |
721 | 746 | else |
722 | 747 | { |
723 | 748 | 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 | + } |
727 | 755 | } |
| 756 | + |
728 | 757 | }); |
729 | | - |
730 | | - } |
731 | | - else |
| 758 | + |
| 759 | + } |
| 760 | + else |
732 | 761 | { |
733 | 762 | if (this.ProviderAsync is IProviderPreReset) |
734 | 763 | { |
735 | 764 | (this.ProviderAsync as IProviderPreReset).OnBeforeReset(); |
736 | 765 | } |
737 | 766 | this.ProviderAsync.OnReset(await this.ProviderAsync.Count); |
738 | 767 | } |
| 768 | + |
| 769 | + lock(this) |
| 770 | + { |
| 771 | + if(_ResetToken == cts) |
| 772 | + { |
| 773 | + _ResetToken = null; |
| 774 | + } |
| 775 | + } |
739 | 776 | } |
740 | 777 |
|
741 | 778 | T InternalGetValue(int index, string selectionContext) |
|
0 commit comments