AsyncTask seems to have a problem with aborting

also, these processes seem to live in the background afterwards and load the computer very heavily until you restart Gamma.

AsyncTaskIssue-Application_2024.12.10-11.01.32
AsyncTaskIssue.vl (18.8 KB)

Yes, this is by design. You need to ask the CancellationToken on your own whether or not to continue execution. You can do so by either asking IsCancellationRequested and for example stop iterating or abort the computation all together with ThrowIfCancellationRequested. For more details see Task Cancellation - .NET | Microsoft Learn

The AsyncTask region manages one task and one corresponding cancellation token at a time. Triggering it will set the previous to cancelled and creates a new one. The in progress output returns true if that one task the region manages isn’t completed yet. It does not look at tasks created by previous triggers.

@Elias, please look closely to the patch and gif.
I used “IsCancelationRequested” and provide it’s output everywhere - to break the loops and to the if region. If I understand you correctly, this is exactly what you are recommending. I understand how it works in C#, but I don’t understand why it doesn’t work in Gamma. Or am I really misunderstanding something and doing something wrong?

upd: That’s how it works:


Thanks!

But anyway, it seems very strange that IsCancellationRequested doesn’t work as expected

You don’t need to throw.

Just put the check for requested cancellation further inside so that it gets checked repeatedly.

The body of asynctask only gets called once, not repeatedly like AsyncLop.

2 Likes

IsCancelationRequested should be inside the loop?

Oh, right, that sounds like it should work.

It all makes sense now, thank you!