title: How can I prevent an event from causing its own event from firing in C#?
body: <p>I have a treeview with checkboxes and I have the following handler for the "AfterCheck" event:</p>
  
  <pre><code>private void trvAvailableFiles_AfterCheck(object sender, TreeViewEventArgs e)
  {
      if (!_isCheckingInProgress)
      {
          trvAvailableFiles.BeginUpdate();
  
          var nodePath = e.Node.Tag.ToString();
          bool isChecked = e.Node.Checked;
          e.Node.Nodes.Clear();
  
          try
          {
              _fileTreeLogic.GetChildNodes(e.Node, true);
              e.Node.ExpandAll();
  
              _isCheckingInProgress = true;
              SetChildrenCheckState(e.Node, isChecked);
              _isCheckingInProgress = false;
  
          }
          finally
          {
              trvAvailableFiles.EndUpdate();
          }
      }
  }
  </code></pre>
  
  <p>If you look closely you'll see that I'm checking if "_isCheckingInProgress".  If it is not, then I proceed and expand all the nodes and call the SetChildrenCheckState() method.  The problem I have encountered is that SetChildrenCheckState() will subsequently cause each child node to all fire the AfterCheck event for its own node.</p>
  
  <p>My question is, is there a more clean way to allow the first AfterCheck event to fire but not the subsequent ones?  It seems kind of hackish that I have to have an instance bool variable to check and set.</p>