title: Named Mutex with await
body: <p>Hence I can't use thread-affine locks with <code>async</code> - how can I guard my resources when running multiple processes?</p>
  <p>For example I've two processes that use a Task below:</p>
  <pre><code> public async Task&lt;bool&gt; MutexWithAsync()
   {
       using (Mutex myMutex = new Mutex(false, &quot;My mutex Name&quot;))
       {
           try
           {
               myMutex.WaitOne();
               await DoSomething();
               return true;
           }
           catch { return false; }
           finally { myMutex.ReleaseMutex(); }
       }
   }
  </code></pre>
  <p>If the method guarded by a Mutex is synchronous then above code will work but with <code>async</code> I will get:</p>
  <blockquote>
  <p>Object synchronization method was called from an unsynchronized block of code.</p>
  </blockquote>
  <p>So is Named Mutex useless with asynchronous code?</p>