fix: fixes incorrect cancellation
This commit is contained in:
+3
-12
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user