diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-07-08 09:45:46 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-07-08 09:45:46 +0300 |
| commit | a2cf6c8d62083a63ee193a1cd206ab345368b242 (patch) | |
| tree | 4f653018e4fb5b4ad806e9d410800489afe411e5 /Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs | |
| parent | c8807df7010acb129997cb7ca130e6b7928ce809 (diff) | |
| parent | f4688d6113dc33deac114bd6999967fec246b8c0 (diff) | |
| download | Tango-a2cf6c8d62083a63ee193a1cd206ab345368b242.tar.gz Tango-a2cf6c8d62083a63ee193a1cd206ab345368b242.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs new file mode 100644 index 000000000..c539273d9 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; + +public static class ObservableCollectionExtensions +{ + public static ObservableCollection<T> ToObservableCollectionAsyncIdle<T>(this ObservableCollection<T> source) + { + var copy = source.ToList(); + ObservableCollection<T> result = new ObservableCollection<T>(); + + foreach (var item in copy) + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + result.Add(item); + }), DispatcherPriority.ContextIdle); + } + + return result; + } + + public static void ReloadAsyncIdle<T>(this ObservableCollection<T> source, Action<int, int> onProgress, Action onComplete = null) + { + var copy = source.ToList(); + source.Clear(); + + int count = copy.Count; + int completed = 0; + + foreach (var item in copy) + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + source.Add(item); + completed++; + + onProgress?.Invoke(completed, count); + + if (completed == count) + { + onComplete?.Invoke(); + } + }), DispatcherPriority.ContextIdle); + } + } +} + |
