title: Equivalent of Objective-C Dispatch Queues in C# .NET approach or idiom
body: <p>I'm a newbie to C# .Net world and am creating a .NET API service that writes to an MS Access database table which does full table locks, there will be up to 20 people writing to the table at the same time (we are getting rid of Access, but not soon enough!).  We need to ensure "writers" don't get locked out.  </p>
  
  <p>While a threading solution would work in most languages, Apple recommends using <a href="https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/ConcurrencyandApplicationDesign/ConcurrencyandApplicationDesign.html#//apple_ref/doc/uid/TP40008091-CH100-SW8" rel="nofollow noreferrer">Dispatch Queues</a> to support concurrency challenges such as above (see excerpt below), where requests to a shared resource are queued and processed one at a time to avoid conflicts.</p>
  
  <p><strong>Is there an equivalent approach or idiom in C#?</strong></p>
  
  <p>I did see <a href="https://stackoverflow.com/questions/17259634/c-sharp-dispatch-queues-like-in-objective-c">this SO</a> question, but it did not really have an answer in the correct context I need.</p>
  
  <p>For more details:</p>
  
  <p><a href="https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/ConcurrencyandApplicationDesign/ConcurrencyandApplicationDesign.html#//apple_ref/doc/uid/TP40008091-CH100-SW8" rel="nofollow noreferrer">Excerpt from Dispatch Queues Objective-C docs</a>:</p>
  
  <p><em>Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue executes tasks either serially or concurrently but always in a first-in, first-out order. (In other words, a dispatch queue always dequeues and starts tasks in the same order in which they were added to the queue.) A serial dispatch queue runs only one task at a time, waiting until that task is complete before dequeuing and starting a new one. By contrast, a concurrent dispatch queue starts as many tasks as it can without waiting for already started tasks to finish.</em></p>
  
  <p><em>Dispatch queues have other benefits:</em></p>
  
  <p><em>They provide a straightforward and simple programming interface. They
     offer automatic and holistic thread pool management. They provide the
     speed of tuned assembly. They are much more memory efficient (because
     thread stacks do not linger in application memory). They do not trap
     to the kernel under load. The asynchronous dispatching of tasks to a
     dispatch queue cannot deadlock the queue. They scale gracefully under
     contention. Serial dispatch queues offer a more efficient alternative
     to locks and other synchronization primitives.</em></p>
  
  <p><strong>The tasks you submit to a dispatch queue must be encapsulated inside either a function or a block object</strong>  </p>
  
  <p>EDIT:
  Turns out that the .Net "Main Loop" or main thread is where you can make requests to process your code.  The main loop is where all the UI work is typically done.  According to this SO question <a href="https://stackoverflow.com/questions/1364809/the-windows-gui-main-loop-in-c-where-is-it" title="quot;SO question on the .Net GUI Main Loop">The Windows GUI Main Loop in C#...where is it?</a> You can also access it via <a href="http://msdn.microsoft.com/en-us/library/ms157902.aspx" rel="nofollow noreferrer" title="Applicaton.Run">Application.Run</a> and <a href="https://stackoverflow.com/questions/418423/threading-timer-vs-forms-timer%20%22Timer%22%20class.">Timer</a> </p>