Search code examples
wpfmultithreadingabort

How to abort threads when application window is closing


I have a WPF application with threads. How do I abort all threads when closing the application?


Solution

  • After you create the thread, set the IsBackground property to true.

    Thread th = new Thread(new ThreadStart(Start));
    th.IsBackground = true;
    th.Start();