title: How do I define an event as occuring whenever a particular set of circumstances are true?
body: <p>Long story short I have two boolean variables called FirstBool and SecondBool. I have a program which uses two delegates to run two methods asynchronously. I am using <code>Console.ReadLine()</code> to keep the parent thread alive while the child thread runs.</p>
  
  <p>When the first method completes, FirstBool is set to true. When the second method completed, SecondBool is set to true.</p>
  
  <p>Long story short, I want to define my event as "<code>FirstBool</code> and <code>SecondBool</code> are both true", and close my program at this time. The only alternative I can see to this is to poll both boolean values until they are both true and then close the program, and polling sucks.</p>
  
  <p>My code is below:</p>
  
  <pre><code>class Program
  {
      private delegate void MyDelegate();
  
      private static bool FirstBool { get; set; }
      private static bool SecondBool { get; set; } 
  
      static void Main(string[] args)
      {
          FirstBool = false;
          SecondBool = false;
  
          MyDelegate firstDelegate = new MyDelegate(FirstMethod);
          MyDelegate secondDelegate = new MyDelegate(SecondMethod);
  
          AsyncCallback myCallback = new AsyncCallback(CallbackMethod);
  
          firstDelegate.BeginInvoke(myCallback, "Zip");
          secondDelegate.BeginInvoke(myCallback, "Line");
  
          Console.ReadLine();
      }
  
      private static void CallbackMethod(IAsyncResult result)
      {
          switch (result.AsyncState.ToString())
          {
              case "Zip":
                  FirstBool = true;
                  break;
              case "Line":
                  SecondBool = true;
                  break;
          }
  
          Console.WriteLine("Callback Method");
      }
  
      private static void FirstMethod()
      {
          Console.WriteLine("First Method");
      }
  
      private static void SecondMethod()
      {
          Console.WriteLine("Second Method");
      }
  }
  </code></pre>
  
  <p>So, long story short, how do I create an event whose definition is "<code>FirstBool</code> is true and <code>SecondBool</code> is true" and run a method on this events occurence?</p>
  
  <p>Thanks</p>