title: Thread was being aborted - C# using queue
body: <p>We have implemented a queue for uploading files to box.net. 
  All files are uploaded successfully. but,I am getting the following exception 1 or 2 times in a week. I couldn't found any cause for this exception. </p>
  
  <p>Exception-Message:</p>
  
  <blockquote>
    <p>Thread was being aborted.</p>
  </blockquote>
  
  <p>Exception-Source:</p>
  
  <blockquote>
    <p>mscorlib</p>
  </blockquote>
  
  <p>Exception-StackTrace:</p>
  
  <blockquote>
    <p>at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj)
    at System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout, Boolean exitContext)
    at System.Threading.Monitor.Wait(Object obj)
    at Box.netAPIWebApp.Service.BoxService.monitorOnUploadQueue() in C:\Project\BackupProjects\BoxNetFileUpload\Box.netAPIWebApp\Source\Service\BoxService.cs:line 90</p>
  </blockquote>
  
  <p>Can any one help on this?</p>
  
  <pre><code>private static readonly BoxService instance = new BoxService();
  
  private Queue&lt;FileCabinetUploadHistory&gt; uploadQueue = new Queue&lt;FileCabinetUploadHistory&gt;();
  
  
  private BoxService()
  {
      Thread monitorThread = new Thread(new ThreadStart(monitorOnUploadQueue));
      monitorThread.Start();
  }
  
  private FileCabinetUploadHistory RemoveFromUploadQueue()
  {
      lock (uploadQueue)
      {
          return uploadQueue.Dequeue();
      }
  }
  
  private void monitorOnUploadQueue()
  {
      FileCabinetUploadHistory fileCabinetUploadHistory = null;
      try
      {
          while (true)
          {
              if (uploadQueue.Count &lt; 1)
              {
                  lock (uploadQueue)
                  {
                      Monitor.Wait(uploadQueue);
                  }
              }
              fileCabinetUploadHistory = uploadQueue.Peek();
  
              if (fileCabinetUploadHistory != null)
              {
                  StartFileUpload(fileCabinetUploadHistory);
              }
          }
      }
      catch (Exception exception)
      {
          log.Error("Error:--&gt; Class name: BoxService, Method name: monitorOnUploadQueue() \n", exception);
      }
  }
  
  public void AddToUploadQueue(FileCabinetUploadHistory fileCabinetUploadHistory)
  {
      lock (uploadQueue)
      {
          if (!uploadQueue.Contains(fileCabinetUploadHistory))
          {
              uploadQueue.Enqueue(fileCabinetUploadHistory);
              Monitor.Pulse(uploadQueue);
          }
      }
  
  }     
  </code></pre>