nabrezzelt
nabrezzelt
CC#
Created by nabrezzelt on 8/31/2024 in #help
Cancel long running task/method
Hi, i have a question: I have a WPF app and want to call the method solver.Solve(); that could take some time but i have not "control" over the method. How can i put that onto another thread that is also cancelable? I tried this but it seems that the cancellationToken is only checked on entering this Task.Run:
await Task.Run(() =>
{
return solver.Solve();
}, cancellationToken);
await Task.Run(() =>
{
return solver.Solve();
}, cancellationToken);
26 replies