2 Commits

Author SHA1 Message Date
Dimitrie Stefanescu 2f2be53bff fix: fixes incorrect cancellation 2021-04-03 18:22:22 +01:00
Dimitrie Stefanescu af6b381578 fix(merge conflicts): fixed merge conflicts (for real) 2021-04-03 18:17:22 +01:00
4 changed files with 8 additions and 35 deletions
@@ -86,24 +86,6 @@ namespace GrasshopperAsyncComponent
Tasks = new List<Task>();
}
public void RequestCancellation()
{
foreach(var token in CancellationSources)
{
token.Cancel();
}
CancellationSources.Clear();
Workers.Clear();
ProgressReports.Clear();
Tasks.Clear();
Interlocked.Exchange(ref SetData, 0);
Message = "Done";
OnDisplayExpired(true);
}
public virtual void DisplayProgress(object sender, System.Timers.ElapsedEventArgs e)
{
if (Workers.Count == 0 || ProgressReports.Values.Count == 0)
@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Speckle Systems")]
[assembly: AssemblyProduct("GrasshopperAsyncComponent")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright AEC Systems © 2020, 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
@@ -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();