title: creating and terminating a thread contained in a collection
body: <p>I have a custom collection (a thread-safe ObservableQueue). I implemented the business logic inside the collection class (i.e. dequeue the items one by one and expose them to the outside). This is working fine. To prevent the collection from blocking the thread it is initialised in, the OnservableQueue implements a thread to perform that work. Now I am not perfectly sure of any pitfalls that could occur.</p>
  
  <p>Is it a bad idea to initialise (not start! only initialise) the thread in the constructor? And what would be a good, if not best, practice of terminating the thread? Note, I dont need to know how to terminate a thread, that is working fine, I am rather interested in weather there is something wrong doing it using the disposable pattern or creating a method which would need to get called to terminate the thread. If implementing <code>IDisposable</code> are there any things I have to take in account regarding the collection/queue?</p>
  
  <p><strong>Edit:</strong> The thread is actually only pre-initialised to prevent <code>NullReferenceException</code> from being thrown in the Enqueue Method, where it is properly initilised again (the Enqueue Method is supposed to check weather a dequeuing thread is running already and if not to start a new one). Note that whenever all items are dequeued and the thread has done its work it will not be alive any longer either, so any time the queue is empty and a new item is added a new thread will get started to process the queue:</p>
  
  <pre class="lang-cs prettyprint-override"><code>if (!_dequeuingThread.IsAlive)
  {
      // start the dequeuing thread
      _dequeuingThread = new Thread(new ThreadStart(StartDequeuing));
      _dequeuingThread.Name = "DeQueueThread";
      _dequeuingThread.Start();
  }
  </code></pre>
  
  <p>The if-statement does need an initialised thread. There are other possible ways of achieving this, but pre-initialising the thread seemed the least bothersome. You see that after checking weather the thread is alive, which it should not when being pre-initialised, it gets initialised again properly.</p>