title: Mutex that not block current(UI) thread
body: <p>I have one little task - i have to create mutex,using tasks and async\await,that not blocking current thread(UI thread).</p>
  
  <p><strong>Mutex interface:</strong></p>
  
  <p>Lock() – returns a Task, wich will be completed only when mutex will become free. This task must be 
  unique per lock to disallow more than 1 unblock per Release() call.
  Release() – release mutex. One and only one of tasks, returned by Lock(), must become completed.
  That mutex have to work in a such way</p>
  
  <pre><code>await mutex.Lock();
  // critical code  
  mutex.Release();
  </code></pre>
  
  <p>I wrote some piece of code(see link in the end),but if briefly describe the problem is:
  I create a class Mutex.
  In the method Lock i do something like that:</p>
  
  <pre><code>await Task.Factory.StartNew(() =&gt;
  {
      mutex.WaitOne();
      UserDispatcher = Dispatcher.CurrentDispatcher;
  });
  </code></pre>
  
  <p>In the method Release i do something like that:</p>
  
  <pre><code>if (mutex != null &amp;&amp; UserDispatcher != null)
  {
      UserDispatcher.Invoke(new Action(() =&gt;
      {
          Console.WriteLine("Releasing");
          mutex.ReleaseMutex();
      }));
  }
  </code></pre>
  
  <p>When i`m trying release mutex,my program just freeze forever. What the problem?</p>
  
  <p>Full code: <a href="https://www.dropbox.com/s/4a370cn1bd2o0nz/MainWindow.xaml.cs?dl=0" rel="nofollow">https://www.dropbox.com/s/4a370cn1bd2o0nz/MainWindow.xaml.cs?dl=0</a></p>
  
  <p>Link to project: <a href="https://www.dropbox.com/sh/qsgle79jdgpr7cd/AAA3MZ6VlTNbUj-isgaQaLE-a?dl=0" rel="nofollow">https://www.dropbox.com/sh/qsgle79jdgpr7cd/AAA3MZ6VlTNbUj-isgaQaLE-a?dl=0</a></p>