title: C# Wait until event listeners have finished
body: <p>In a C# winforms program, I have an event that fires when someone attempts to rename a project. In the EventArgs for that event, I have a "Cancel" property that the event listeners can set to true to (ideally) cancel the rename (if the name is already in use, for example):</p>
  
  <pre><code>ProjectRenamedEventArgs args = new ProjectRenamedEventArgs(oldName, newName);
  
  if (NameChanged != null)
      NameChanged(this, args);
  
  if (args.Cancel)
  {
      // Cancel
  }
  else
  {
      // Continue
  }
  </code></pre>
  
  <p>The problem is, the "if (args.Cancel...." line is never reached. I'm guessing that execution is continuing right after the event is fired, and thus args.Cancel is always false so the rename always happens. How would I make execution halt until all of the event listeners have finished their work (giving args.Cancel a chance to be set to true).</p>
  
  <p>I am assuming this is possible because many of the windows forms EventArgs have a Cancel property that allow for whatever just happened to be cancelled (changing the label on a TreeView's TreeNode, for example).</p>