aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2018-07-07 15:02:20 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2018-07-07 15:02:20 +0300
commit4ca8cee91fb46977b75e8329c18d9b6a4654b12e (patch)
treec2a0473f30d9302f4b8eea21f90106d24ba23461 /Software/Visual_Studio/PPC/Tango.PPC.Common/ExtensionMethods/ObservableCollectionExtensions.cs
parentbed649c7492655c0137237c910b200e053bfa119 (diff)
downloadTango-4ca8cee91fb46977b75e8329c18d9b6a4654b12e.tar.gz
Tango-4ca8cee91fb46977b75e8329c18d9b6a4654b12e.zip
Working on PPC jobs loading performance...
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.cs53
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);
+ }
+ }
+}
+