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 562423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:33:11+00:00 2026-05-13T12:33:11+00:00

I am trying to adapt an existing program (internally written) to use a different

  • 0

I am trying to adapt an existing program (internally written) to use a different library than it originally did. I’ve abstracted most of library-specific code away (seems to be the easier part).

The issue is, the old library would execute a call using a blocking method, and our internal program is expecting a blocking method to be called, but the new library uses an async method.

I was wondering what the best practice would be for waiting for the async operation to complete. My first thought was to have a boolean flag called completed, and spin in a while loop until completed == true.

I should note that this is for a quick proof of concept I’m trying to put together for my stakeholder, and if the stakeholders sign off on the project, I’m going to rewrite the offending part of our program. But for the time being, I need to just wait for the block the function calling the async method until the async call is complete

  • 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-05-13T12:33:11+00:00Added an answer on May 13, 2026 at 12:33 pm

    Instead of a flag, I’d think you’d want to use something like a mutex.

    In order to do this, that library needs to have an event to notify you once your async call is done. It would look like this:

    1. Create your mutex
    2. In your async complete method, add in ‘myMutex.Release();”
    3. In your main method, after you call the async method, add in “myMutex.WaitOne();”. This will block the thread until your async call is complete.

    It’s been a while since I’ve used this stuff, but I’m pretty sure that’s how it should work.

    edit: Oops, I think I was thinking of a semaphore, not mutex:

        private static Semaphore mySemaphore = new Semaphore(0, 1);
    
        static void Main(string[] args)
        {
            Console.WriteLine("Waiting on async call");
            (new Thread(ASyncCallCompleted)).Start();
            mySemaphore.WaitOne();
            Console.WriteLine("Waiting Completed");
        }
    
        private static void ASyncCallCompleted()
        {
            Thread.Sleep(5000);
            mySemaphore.Release();
        }
    

    edit #2: Per Thorarin’s suggestion; it sounds like this class was designed to handle situations like this in .Net:

        private static AutoResetEvent mySync = new AutoResetEvent(false);
    
        static void Main(string[] args)
        {
            Console.WriteLine("Waiting on async call");
            (new Thread(ASyncCallCompleted)).Start();
            mySync.WaitOne();
            Console.WriteLine("Waiting Completed");
            Console.Read();
        }
    
        private static void ASyncCallCompleted()
        {
            Thread.Sleep(5000);
            mySync.Set();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.