title: WeakEventManager RemoveHandler does not always work when called asynchronously
body: <p>I am using the <a href="https://msdn.microsoft.com/en-us/library/hh199438(v=vs.110).aspx" rel="noreferrer"><code>WeakEventManager&lt;TEventSource, TEventArgs&gt;</code></a> class in order to subscribe to events in C#. Event subscription works fine, however calling <a href="https://msdn.microsoft.com/en-us/library/hh161304%28v=vs.110%29.aspx" rel="noreferrer"><code>WeakEventManager&lt;TEventSource, TEventArgs&gt;.RemoveHandler</code></a> from a <code>Task</code> does not always remove the handler - most (but not all) of the time the handler is still executed when the event fires.</p>
  
  <p>This is illustrated in the following example.</p>
  
  <pre><code>public class EventSource
  {
      public event EventHandler Fired = delegate { };
  
      public void FireEvent()
      {
          Fired(this, EventArgs.Empty);
      }
  }
  
  class Program
  {
      private static bool added, removed, handled;
  
      static void Main(string[] args)
      {
          for (int i = 1; i &lt;= 100; i++)
          {
              added = removed = handled = false;
  
              var source = new EventSource();
  
              AddHandlerAsync(source).Wait();
  
              RemoveHandlerAsync(source).Wait();
  
              source.FireEvent();
  
              if (removed &amp;&amp; handled) Console.WriteLine("Event handled after removal!");
              else                    Console.WriteLine("----------------------------");
          }
  
          Console.ReadKey();
      }
  
      private async static Task AddHandlerAsync(EventSource source)
      {
          await Task.Run(() =&gt;
          {
              System.Windows.WeakEventManager&lt;EventSource, EventArgs&gt;.AddHandler(source, "Fired", HandleEvent);
              added = true;
          });
      }
  
      private async static Task RemoveHandlerAsync(EventSource source)
      {
          await Task.Run(() =&gt;
          {
              System.Windows.WeakEventManager&lt;EventSource, EventArgs&gt;.RemoveHandler(source, "Fired", HandleEvent);
              removed = true;
          });
      }
  
      private static void HandleEvent(object sender, EventArgs e)
      {
          handled = true;
      }
  }
  </code></pre>
  
  <p>The handler is removed all of the time, however in most cases the event is still handled.</p>
  
  <p>Am I making an error in the way that these methods are called? Do these methods support being called asynchronously? Is there an alternative approach that would work?</p>
  
  <p>Many thanks for your help in advance.</p>