title: Is there a way to force the application to run as single threaded?
body: <p>We have an old project that we are supporting and there is an issue that occurs most probably due to multi-threading.
  The original implementer 'fixed' it by doing a <code>Thread.sleep</code> before executing the problematic section.
  The workaround works but as the section is inside a loop the <code>thread.sleep</code> adds multiple minutes to the time it takes for the section to finish.</p>
  
  <p>In the last month we have been we have been experimenting with lower values for the sleep but we wish to find the root cause. During our investigations we were doing <code>lock</code> on private objects wherever we felt like that would help.
  We looked for anything that might be spawning additional threads - found none.
  No Thread.start and no ThreadPool usage.
  What is confusing us is that during debugging we find our main thread in the middle of about 8 other threads that we don't know who spawned them.
  These are background threads so first thought I had was the threadpool but as I mentioned no mention of it in the code.</p>
  
  <p>It is .net 2.0 so no <code>Async</code>s.
  This is just a part of the bigger application so it is a windows service but we run it as CMD to be able to debug it easily The main application itself is a windows forms desktop app.
  It also uses COM+ components if that is any help.</p>
  
  <p>I've tried <code>[STA]</code> instead of <code>[MTA]</code>.
  Also Locking as aforementioned.
  <code>MemoryBarrier</code>s as well.</p>
  
  <p>We still get the issue.</p>
  
  <p>The issue is basically corrupted datasets and nulls in objects where they shouldn't be.
  It happens in about once every 25-100 iterations so reproduction is not straight forward but we have devised a test specifically for this issue to try to reproduce it.</p>
  
  <p>All that is pointing us into the direction of thread issues.</p>
  
  <p>Back to the original question -
  Who could possibly by spawning those additional threads and how do we prevent these threads for being created?</p>
  
  <p><a href="https://i.stack.imgur.com/Y4YLt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Y4YLt.png" alt="enter image description here"></a></p>
  
  <p>Please note the threads marked with red - those are background threads and as far as we can see no mention of them in the code.</p>
  
  <p>The suspected thread in the screenshot is actively modifying the cols in the <code>dataset</code>. Problem is - the methods calling the <code>SetColValueOnRow</code> function that the thread is executing are typical and don't use any kind of threading.</p>
  
  <p>The CPU affinity for this application is set to 1 Core [part of the original work-around]</p>
  
  <p>Thanks</p>
  
  <p>Edit: The database is oracle 12c but the issues we face happen before writing to the database.
  They usually happen in DataSets where a whole record or a few of its columns can be wiped once every few testing iterations</p>