From 2f2be53bffd2402337ba40d65bb5b619d1161b3e Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Sat, 3 Apr 2021 18:22:22 +0100 Subject: [PATCH] fix: fixes incorrect cancellation --- .../Sample_PrimeCalculatorAsyncComponent.cs | 15 +++------------ .../Sample_UslessCyclesComponent.cs | 4 ++-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_PrimeCalculatorAsyncComponent.cs b/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_PrimeCalculatorAsyncComponent.cs index 105cc9c..073222f 100755 --- a/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_PrimeCalculatorAsyncComponent.cs +++ b/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_PrimeCalculatorAsyncComponent.cs @@ -33,15 +33,6 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations pManager.AddNumberParameter("Output", "O", "The n-th prime number.", GH_ParamAccess.item); } - protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu) - { - base.AppendAdditionalComponentMenuItems(menu); - Menu_AppendItem(menu, "Cancel", (s, e) => - { - this.RequestCancellation(); - }); - } - public override void AppendAdditionalMenuItems(ToolStripDropDown menu) { base.AppendAdditionalMenuItems(menu); @@ -62,7 +53,7 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations public override void DoWork(Action ReportProgress, Action Done) { // 👉 Checking for cancellation! - if (CancellationToken.IsCancellationRequested) { Done(); return; } + if (CancellationToken.IsCancellationRequested) { return; } int count = 0; long a = 2; @@ -71,14 +62,14 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations while (count < TheNthPrime) { // 👉 Checking for cancellation! - if (CancellationToken.IsCancellationRequested) { Done(); return; } + if (CancellationToken.IsCancellationRequested) { return; } long b = 2; int prime = 1;// to check if found a prime while (b * b <= a) { // 👉 Checking for cancellation! - if (CancellationToken.IsCancellationRequested) { Done(); return; } + if (CancellationToken.IsCancellationRequested) {return; } if (a % b == 0) { diff --git a/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_UslessCyclesComponent.cs b/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_UslessCyclesComponent.cs index 498b144..16f593c 100755 --- a/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_UslessCyclesComponent.cs +++ b/GrasshopperAsyncComponentDemo/SampleImplementations/Sample_UslessCyclesComponent.cs @@ -52,7 +52,7 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations public override void DoWork(Action ReportProgress, Action Done) { // Checking for cancellation - if (CancellationToken.IsCancellationRequested) { Done(); return; } + if (CancellationToken.IsCancellationRequested) { return; } for (int i = 0; i <= MaxIterations; i++) { @@ -63,7 +63,7 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations ReportProgress(Id, ((double)(i + 1) / (double)MaxIterations)); // Checking for cancellation - if (CancellationToken.IsCancellationRequested) { Done(); return; } + if (CancellationToken.IsCancellationRequested) { return; } } Done();