4

How can I stop RunAsync?

CancellatioTokenSource cts = new CancellationTokenSource();
//I thought that it's must work, but it don't
var script = CSharpScript.Create(code: someCode);
await script.RunAsync(cancelletionToken: cts.Token);

void button_click()
{
   cts.Cancel()
}

How else can I do this. And for why such methods need cancellationToken parameter?

0

1 Answer 1

3

You must do it before the await call, which blocks execution until yout get results, e.g.:

var task = script.RunAsync(cancelletionToken: cts.Token);

cts.Cancel();

var result = await task;
Sign up to request clarification or add additional context in comments.

2 Comments

cts.Cancel() is already in a separate function. It should also be on the UI thread.
Cancellation token can only interrupt RunAsync itself, while it's busy compiling. This will not interrupt running script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.