title: GC.WaitForPendingFinalizers not working in async method?
body: <p>I have some unit tests to verify if objects using WeakReferences work correctly. After refactoring these objects to work asynchronously the unit tests fail. This seems to be caused by GC.WaitForPendingFinalizers not working (or working differently?) when using async.</p>
  
  <p>To check this I created a simple WPF app with two buttons, one with a regular Click event and one with an async click event.</p>
  
  <p>When I press the NormalGCTest button "object garbage collected: True" is shown.</p>
  
  <p>But when I press the AsyncGCTest button "object garbage collected: False" is shown.</p>
  
  <p>What is going on? Is there a way to force a full garbage collection in my tests?</p>
  
  <pre><code>    private void NormalGCTest(object sender, RoutedEventArgs e)
      {
          var temp1 = new object();
          var temp2 = new WeakReference(temp1);
          temp1 = null;
          GC.Collect();
          GC.WaitForPendingFinalizers();
          temp1 = temp2.Target;
          System.Diagnostics.Debug.WriteLine("object garbage collected: {0}", temp1 == null);
      }
  
      private async void AsyncGCTest(object sender, RoutedEventArgs e)
      {
          var temp1 = new object();
          var temp2 = new WeakReference(temp1);
          temp1 = null;
          GC.Collect();
          GC.WaitForPendingFinalizers();
          temp1 = temp2.Target;
          System.Diagnostics.Debug.WriteLine("object garbage collected: {0}", temp1 == null);
          await Task.Delay(0);
      }
  </code></pre>