© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
25 replies
nabrezzelt

Cancel long running task/method

Hi, i have a question: I have a WPF app and want to call the method
solver.Solve();
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);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ CancellationtokenSource and Cancel Task
C#CC# / help
2y ago
❔ Cancel task on nested exception
C#CC# / help
3y ago
❔ ✅ Best practice for tracking progress for long running method
C#CC# / help
3y ago