Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:18:31+00:00 2026-06-02T05:18:31+00:00

Long story short I have two boolean variables called FirstBool and SecondBool. I have

  • 0

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 Console.ReadLine() to keep the parent thread alive while the child thread runs.

When the first method completes, FirstBool is set to true. When the second method completed, SecondBool is set to true.

Long story short, I want to define my event as “FirstBool and SecondBool 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.

My code is below:

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");
    }
}

So, long story short, how do I create an event whose definition is “FirstBool is true and SecondBool is true” and run a method on this events occurence?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:18:32+00:00Added an answer on June 2, 2026 at 5:18 am

    If you have access to .NET 4, then you can very easily accomplish this with the Task Parallel Library:

    var taskOne = Task.Factory.StartNew(() =>
       {
           // Do Stuff
       });
    
    var taskTwo = Task.Factory.StartNew(() =>
       {
           // Do Other Stuff
       });
    
    Task.WaitAll(taskOne, taskTwo);
    
    // Quit
    

    If you’re using an older version of .NET, then you simply need to call the EndInvoke method to wait for the asynchronous calls to complete:

     SomeDelegate x = SomeMethod;
     SomeDelegate y = SomeOtherMethod;
    
     var iar1 = x.BeginInvoke(null, null);
     var iar2 = y.BeginInvoke(null, null);
    
     // Program would still be executing here...
    
     x.EndInvoke(iar1);
     y.EndInvoke(iar2);
    
     // Quit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, I have a LaunchActivity which is always called by LAUNCHER (i.e.
Long story short, I have a long code that uses jQuery. Lots of files,
Long story short, I have two regex patterns. One pattern matches things that I
Long story short -- we have 2 webservers that run a 3rd party asp.net
To make a long story short I have to use processing in a class
Long story short, I have a substantial Python application that, among other things, does
Long story short, I have an ASP.NET application I'm trying to debug and at
So long story short, i have some forms (2) of them that, need different
Hey, long story short I have inherited some terrible code. As a result a
Long story short, I have a struct (see below) that contains exactly one field:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.