fix: fixes incorrect cancellation

This commit is contained in:
Dimitrie Stefanescu
2021-04-03 18:22:22 +01:00
parent af6b381578
commit 2f2be53bff
2 changed files with 5 additions and 14 deletions
@@ -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<string, double> 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)
{
@@ -52,7 +52,7 @@ namespace GrasshopperAsyncComponentDemo.SampleImplementations
public override void DoWork(Action<string, double> 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();