title: Using Delegates in C# Asynchronously
body: <p>I have the following delegate</p>
  
  <pre><code>delegate void UpdateFileDelegate(long maxFileID);
  </code></pre>
  
  <p>That I am calling from a WinForms app like so</p>
  
  <pre><code>UpdateFileDelegate FD = new UpdateFileDelegate(ClassInstance.UpdateFile);
  FD.BeginInvoke(longIDNumber,null,null);
  </code></pre>
  
  <p>It runs asynchronously but the question I have is how can I tell when the Method is done executing so I can let the end user know?</p>
  
  <p>Update: 
  Thanks to the recommendations below the following code does the trick.
  Also this <a href="http://www.yoda.arachsys.com/csharp/events.html" rel="nofollow noreferrer">article</a> was helpful in getting me to understand what my code is actually doing.</p>
  
  <pre><code>delegate void UpdateFileDelegate(long maxFileID);
  UpdateFileDelegate FB = new UpdateFileDelegate(ClassInstance.UpdateFile);
  AsyncCallback callback = new AsyncCallback(this.CallBackMethod);
  IAsyncResult result = FB.BeginInvoke(longIDNumber);
  
  private void CallBackMethod(IAsyncResult result)
      {
       AsyncResult delegateResult = (AsyncResult)result;
  
       UpdateFileDelegate fd = (UpdateFileDelegate)delegateResult.AsyncDelegate;
       fd.EndInvoke(result);
       MessageBox.Show("All Done!");
      }
  </code></pre>