title: Question about terminating a thread cleanly in .NET
body: <p>I understand Thread.Abort() is evil from the multitude of articles I've read on the topic, so I'm currently in the process of ripping out all of my abort's in order to replace it for a cleaner way; and after comparing user strategies from people here on stackoverflow and then after reading <strong>&quot;<a href="http://msdn.microsoft.com/en-us/library/7a2f3ay4%28VS.80%29.aspx" rel="nofollow noreferrer">How to: Create and Terminate Threads (C# Programming Guide)</a>&quot;</strong> from MSDN both which state an approach very much the same -- which is to use a <code>volatile bool</code> approach checking strategy, which is nice, but I still have a few questions....</p>
  <p>Immediately what stands out to me here, is what if you do not have a simple worker process which is just running a loop of crunching code? For instance for me, my process is a background file uploader process, I do in fact loop through each file, so that's something, and sure I could add my <code>while (!_shouldStop)</code> at the top which covers me every loop iteration, but I have many more business processes which occur before it hits it's next loop iteration, I want this cancel procedure to be snappy; don't tell me I need to sprinkle these while loops every 4-5 lines down throughout my entire worker function?!</p>
  <p>I really hope there is a better way, could somebody please advise me on if this is in fact, the correct [and only?] approach to do this, or strategies they have used in the past to achieve what I am after.</p>
  <p>Thanks gang.</p>
  <p>Further reading: <a href="https://stackoverflow.com/questions/1051838/killing-a-thread-c">All these SO responses</a> assume the worker thread will loop.  That doesn't sit comfortably with me.  What if it is a linear, but timely background operation?</p>