public static bool IsAborted(Service service) { return(Aborted.FirstOrDefault(s => s == service) != null); }
/// <summary> /// Called on algorithm abort. /// </summary> /// <param name="args"><see cref="F:EventArgs.Empty"/>.</param> protected virtual void OnAborted([NotNull] EventArgs args) { Debug.Assert(args != null); Aborted?.Invoke(this, args); }
public void OnAborted(object sender, EventArgs e) { _moveThread?.Abort(); Aborted?.Invoke(this, EventArgs.Empty); }
public async Task <List <DuplicatesResult> > Find(int maxParallelism = 4) { var ts = new CancellationTokenSource(); cancellationTokens.Add(ts); CancellationToken ct = ts.Token; try { return(await Task.Run(() => { PrepareCompareValues?.Invoke(this, false); OnPrepareCompareValue(ct, maxParallelism); PrepareCompareValues?.Invoke(this, true); var result = new List <DuplicatesResult>(); ParallelOptions po = new ParallelOptions { CancellationToken = ct, MaxDegreeOfParallelism = maxParallelism }; try { int itemCounter = 0; decimal progressValue = 0; List <string> cacheIndexValues = new List <string>(); if (CacheDuplicateResult != null) { result = CacheDuplicateResult.DuplicatesResults; cacheIndexValues = CacheDuplicateResult.IndexCollection; } Parallel.For(0, Files.Count, po, (int index) => { string file = Files[index]; System.Diagnostics.Debug.Print($"INDEX => {index}"); if (!cacheIndexValues.Contains(file.ToUpper())) { if (itemCounter == 0) { ProcessFileProgress?.Invoke(this, 0); ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(0, result, index, itemCounter, cacheIndexValues)); } cacheIndexValues.Add(file.ToUpper()); ProcessFile?.Invoke(this, file); var dup = OnCompareDuplicates(file, index); if (dup != null) { result.Add(dup); } var progressValue2 = Math.Round(((decimal)itemCounter / (decimal)Files.Count * 100), 2); if (progressValue2 > progressValue) { progressValue = progressValue2; } ProcessFileProgress?.Invoke(this, progressValue); ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(progressValue, result, index, itemCounter, cacheIndexValues)); } else { System.Diagnostics.Debug.Print($"Already collected File:{file}"); } itemCounter++; }); ProcessFileProgress?.Invoke(this, 100); ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(100, result, -1, itemCounter, cacheIndexValues)); } catch (Exception ex) { if (ex is AggregateException || ex is ObjectDisposedException || ex is OperationCanceledException) { Aborted?.Invoke(this, EventArgs.Empty); return null; } throw; } cancellationTokens.Remove(ts); return result; }, ct)); } catch (Exception ex) { if (ex is AggregateException || ex is ObjectDisposedException || ex is OperationCanceledException) { Aborted?.Invoke(this, EventArgs.Empty); return(null); } throw; } }
private void OnAborted() { Aborted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Abort resource loading. /// </summary> protected virtual bool OnAbort(PartialResource res, Exception e) { Aborted?.Invoke(this, e); return(false); }
/// <summary> /// Raises the <see cref="Aborted"/> event. /// </summary> /// <param name="e">The event arguments.</param> protected virtual void OnAborted(ChaosAbortedEventArgs e) => Aborted?.Invoke(this, e);