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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:16:03+00:00 2026-05-23T04:16:03+00:00

I need to Download a File from a Https Source. I’ll do this asynchron

  • 0

I need to Download a File from a Https Source.
I’ll do this asynchron like this (works so far):

void doChecksbeforDownload(){
//Do some Checks
   DownloadFileAsync();

}

void DownloadFileAsync(){
     ...
     ... 
     this.client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
     this.client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
     this.client.UploadStringAsync(new Uri(url), "POST", PostParameter);
     ...
     ...
}

and call the client_UploadStringCompleted() Method when finished:

void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
       //Do Check here
    }

So far so good. Now I put all this in a class “Functions” and call the Method like this:

 Functions f = new Functions();
 f.doChecksbeforeDownload();

I want doChecksbeforeDownload() to wait until the clientUloadStringCompleted is FINISHED.

How do I do I tell doChecksbeforeDownload to wait until the the Async call in DownloadFilesAsync is done and ready.

  1. Call doChecksbeforeDownload()
  2. ChecksbeforeDownload()->DownloadFileAsync()
  3. ChecksbeforeDownload()->Waits…….
  4. DownloadFileAsync() -> Completet & Ready
  5. ChecksbeforeDownload()->returns FOO to Main Class

Are there any best practices / examples to achieve this? I stuck in this point.

Thanks in advance

Hannes

  • 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-23T04:16:03+00:00Added an answer on May 23, 2026 at 4:16 am

    You will want to use the synchronization objects exposed in .NET.

    Check out this link. Here’s an excerpt:

    class BasicWaitHandle
    {
      static EventWaitHandle _waitHandle = new AutoResetEvent (false);
    
      static void Main()
      {
        new Thread (Waiter).Start();
        Thread.Sleep (1000);                  // Pause for a second...
        _waitHandle.Set();                    // Wake up the Waiter.
      }
    
      static void Waiter()
      {
        Console.WriteLine ("Waiting...");
        _waitHandle.WaitOne();                // Wait for notification
        Console.WriteLine ("Notified");
      }
    }
    

    NOTE: Be careful making your reset events static, etc. Then you’ll be introducing thread safety issues. The above example is only static for simplicity.

    In your case, you’d want to make to make the autoreset event a member of your class that is performing the asynchronous. In your function, after you start the asynchronous call, wait on your handle. In the completion event, set your event which should unblock your wait handle.

    Consider that you may want to introduce timeouts for the call to WaitOne(), etc.

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

Sidebar

Related Questions

I need to download a file from an url and save it to local
I am trying to download Android source code for Contact,Dialer and CallLog applications from
I've got a php page which handles requets for file downloads. I need to
I need to periodically download, extract and save the contents of http://data.dot.state.mn.us/dds/det_sample.xml.gz to disk.
I need customers to be able to download PDFs of letters that have been
I have a need to allow for a user to download an event that
Quick (and hopefully easy) question: I need to trigger a download of a PDF
In C#, if I need to open an HTTP connection, download XML and get
With ANTLR, I get some java class files after compilation. And I need to
I'm a Perl programmer with some nice scripts that go fetch HTTP pages (from

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.