diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-07-07 15:02:20 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-07-07 15:02:20 +0300 |
| commit | 4ca8cee91fb46977b75e8329c18d9b6a4654b12e (patch) | |
| tree | c2a0473f30d9302f4b8eea21f90106d24ba23461 /Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods | |
| parent | bed649c7492655c0137237c910b200e053bfa119 (diff) | |
| download | Tango-4ca8cee91fb46977b75e8329c18d9b6a4654b12e.tar.gz Tango-4ca8cee91fb46977b75e8329c18d9b6a4654b12e.zip | |
Working on PPC jobs loading performance...
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/IListExtensions.cs | 26 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs | 53 |
2 files changed, 79 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/IListExtensions.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/IListExtensions.cs new file mode 100644 index 000000000..fdf07ccff --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/IListExtensions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; + +public static class IListExtensions +{ + public static IList<T> ToListAsyncIdle<T>(this IList<T> source) + { + var copy = source.ToList(); + IList<T> result = new List<T>(); + + foreach (var item in copy) + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + result.Add(item); + }), DispatcherPriority.ContextIdle); + } + + return result; + } +} 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); + } + } +} + |
