I use WPF to create a window and meanwhile create a new task to implement time-costing job which will also block the task before finishing.
Now I want to use a button that can cancel and exit the blocked task though it's still active. The Microsoft document recommends to use CancellationToken
to cancel a task but the problem is I can't check whether the IsCancellationRequested
flag is triggered because the blocked task has no loop to detect the flag and can't exit the task normally. I also try to use Thread.Abort()
to force close the thread but it causes PlatformNotSupportedException
.
So I wonder if there's any method to cancel the blocked task/thread and its child task/thread or if WPF privides any approach to close all the task/thread except for the main UI thread.