Have you considered using an asynchronous Task coupled with IProgress and a CancellationToken?
See my code sample
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a C# program with this line inside a loop:
Dispatcher.Invoke(updateProgressBar1, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, j });
when I want to close the application by clicking the close button in the title bar, the application continues to run for a long time... how can I abort the work in the background?? How in general can I close all threads?
Thanks!
Juan
Have you considered using an asynchronous Task coupled with IProgress and a CancellationToken?
See my code sample
First I need an answer to my question then I can refactor...
Dispatcher does not use threads, it always the thread the Dispatcher is created on. you probably want to shutdown the dispatcher, so it no longer processes the queue.
Dispatcher.InvokeShutdown();
if you started a separate thread to run the Dispatcher, then you can kill that thread if you saved the thread handle.
Dispatcher.InvokeShutdown() does not stop the application!!
You don’t explain your app. How was dispatcher setup? Do you create any threads? How are you closing your app?
The Dispatch.Shutdown() does not stop the current background process, just stops doing any more in the queue.