protected void updateTools(PackageChange change, int index) { PackageUpdate update = new PackageUpdate { change = change, index = index }; if (!pendingUpdates.Contains(update)) { pendingUpdates.Add(update); Task task = Task.Delay(queuingDelay); taskCompletion[task.Id] = false; tasks.Add(task); task.ContinueWith(x => { taskCompletion[x.Id] = true; if (tasks.TrueForAll(t => taskCompletion[t.Id])) { tasks.Clear(); taskCompletion.Clear(); foreach (var item in Tools) { item.handleUpdate(pendingUpdates.ToList()); } pendingUpdates.Clear(); OnPropertyChanged(nameof(IsModified)); } }, TaskScheduler.FromCurrentSynchronizationContext()); } }
protected void updateTools(PackageChange change, int index) { PackageUpdate update = new PackageUpdate { change = change, index = index }; if (!pendingUpdates.Contains(update)) { pendingUpdates.Add(update); Task task = Task.Delay(queuingDelay); taskCompletion[task.Id] = false; tasks.Add(task); task.ContinueWithOnUIThread(x => { taskCompletion[x.Id] = true; if (tasks.TrueForAll(t => taskCompletion[t.Id])) { tasks.Clear(); taskCompletion.Clear(); var removedImports = pendingUpdates.Where(u => u.change == PackageChange.ImportRemove).Select(u => u.index).ToList(); var removedExports = pendingUpdates.Where(u => u.change == PackageChange.ExportRemove).Select(u => u.index).ToList(); var pendingUpdatesList = new List <PackageUpdate>(); foreach (PackageUpdate upd in pendingUpdates) { switch (upd.change) { case PackageChange.ExportAdd: case PackageChange.ExportData: case PackageChange.ExportHeader: { if (!removedExports.Contains(upd.index)) { pendingUpdatesList.Add(upd); } break; } case PackageChange.ImportAdd: case PackageChange.Import: { if (!removedImports.Contains(upd.index)) { pendingUpdatesList.Add(upd); } break; } default: pendingUpdatesList.Add(upd); break; } } pendingUpdates.Clear(); foreach (var item in Tools) { item.handleUpdate(pendingUpdatesList); } OnPropertyChanged(nameof(IsModified)); } }); } }
protected void updateTools(PackageChange change, int index) { PackageUpdate update = new PackageUpdate { change = change, index = index }; if (!pendingUpdates.Contains(update)) { pendingUpdates.Add(update); Task task = Task.Delay(queuingDelay); taskCompletion[task.Id] = false; tasks.Add(task); task.ContinueWith(x => { taskCompletion[x.Id] = true; if (tasks.TrueForAll(t => taskCompletion[t.Id])) { tasks.Clear(); taskCompletion.Clear(); foreach (var item in Tools) { item.handleUpdate(pendingUpdates.ToList()); } pendingUpdates.Clear(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsModified))); } }, TaskScheduler.FromCurrentSynchronizationContext()); } }