title: Thread abort exception in WPF
body: <p>I am trying to implement loaders in my <code>WPF</code> application. During some heavy operations, the UI thread gets frozen, so I had to implement the loaders using threads. Each time the loader loads, a new thread is created and this thread gets aborted (manually) when the loader sets off. The problem I am facing is that sometimes the application gets crashed giving a <code>ThreadAbortException</code>.</p>
  
  <p>This is the code to start the loader :</p>
  
  <pre><code>try
          {
              //if(newWindowThread !=null &amp;&amp; !newWindowThread.IsAlive) { }
              newWindowThread = new Thread(new ThreadStart(() =&gt;
              {
                  try
                  {
                      // Create and show the Window
                      awq = new BusyIndicatorDisguise(BusyMessage);
                      awq.Show(); // &lt;== POINT WHERE THE EXCEPTION IS THROWN
                      //Start the Dispatcher Processing
                      if (!isDispatcherStarted)
                      {
                          var a = Thread.CurrentThread;
                          var b = Dispatcher.CurrentDispatcher;
                          //isDispatcherStarted = true;
                          Dispatcher.Run();
                      }
  
                  }
                  catch (ThreadAbortException thEx)
                  {
  
                  }
                  catch (Exception ex)
                  {
  
                  }
              }
              ));
              // Set the apartment state
              newWindowThread.SetApartmentState(ApartmentState.STA);
              // Make the thread a background thread
              newWindowThread.IsBackground = true;
              // Start the thread
              newWindowThread.Start();
          }
          catch (Exception ex)
          {
  
          }
  </code></pre>
  
  <p>This code is for stopping the loader :</p>
  
  <pre><code>if (newWindowThread != null &amp;&amp; newWindowThread.IsAlive)
          {          
              newWindowThread.Abort();              
          }
  </code></pre>
  
  <p>I am not able to catch this exception in my catch block. Maybe because it is on a different thread.
  I want to know how can I avoid the ThreadAbortException</p>