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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:51:03+00:00 2026-05-13T15:51:03+00:00

I am developing a C# Winforms application, part of the application will be uploading

  • 0

I am developing a C# Winforms application, part of the application will be uploading files to a webserver using AsyncUpload (using it,due to the need to use a porgress callback) , In the C# program

i got a simple for loop that calls The Uploading function

 for(int i=0;i < 10 ; i++)
{
  Uploadfun();
}

And the fun does some magic:

Uploadfun()
  { 
  // Logic comes here

   // webClient.UploadFileAsync runs a 2nd thread to perform upload .. 
   webClient.UploadFileAsync(uri, "PUT", fileNameOnHD);  

 }

And a callback that gets called when the Async upload is done

Upload_Completed_callback()
{
  //Callback event
}

Edit

The logic sequence:

  1. Fun gets called (from loop)
  2. Fun logic is executed and done..
  3. Goes back to for loop
  4. Callback will be called eventually, when UploadFileAsync (which is running some logic in another thread) will end

The problem is on the 3rd point, when the execution moves back to the for loop, i need to block the loop from continuing until the callback get called.

  • 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-13T15:51:03+00:00Added an answer on May 13, 2026 at 3:51 pm

    So if I understand correctly, you want to call UploadFileAsync then block until the async call has hit your callback. If so, I’d use AutoResetEvent i.e

    private readonly AutoResetEvent _signal = new AutoResetEvent(false); 
    
    fun()
      { 
      // Logic comes here
    
       // runs a 2nd thread to perform upload .. calling "callback()" when done
       webClient.UploadFileAsync(uri, "PUT", fileNameOnHD);  
    
       _signal.WaitOne();   // wait for the async call to complete and hit the callback     
     }
    
    
    
    callback()
     {
       //Callback event
       _signal.Set(); // signal that the async upload completed
     }
    

    Using AutoResetEvent means that the state gets automatically reset after Set has been called and a waiting thread receives the signal via WaitOne

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application in c# using winforms and I need to print some
Folks, We are developing an application that is part a downloadable WinForms application that
We are developing a multilingual Winforms application using visual studio 2008. I am trying
I'm developing a .NET application that will have both a WinForms and a Silverlight
I'm using WinForms and C#. The application I am developing draws rows of rectangles
I am developing a winforms application using .NET 2.0 and Sql Server 2005. I
I am currently developing a Winforms Application that will run on a very specific
I'm developing application in WPF but some components are written using WinForms. I wan't
I'm developing a VB.NET WinForms application, and I'm using lots of small 16x16 32bit
I am developing a Client-Server application using C# .NET Winforms with SQL Server 2008.

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.