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

  • Home
  • SEARCH
  • 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 7034989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:15:05+00:00 2026-05-28T01:15:05+00:00

I have a winforms app that is making asyncronous WebClient calls with a callback

  • 0

I have a winforms app that is making asyncronous WebClient calls with a callback procedures as follows…

using (var wc = new WebClient())
{
    wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
    wc.DownloadProgressChanged+=new DownloadProgressChangedEventHandler(DownloadProgressCallback);
    //other stuff
    wc.DownloadFileAsync(uri, fullLocalPath);
}

I want to create a global exception handler so I have defined an application event for it…

[STAThread]
static void Main()
{
    Application.ThreadException += new ThreadExceptionEventHandler(ApplicationThreadException);
    //other stuff
    Application.Exit();

}

private static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
{
    // Do logging or whatever here

    Application.Exit();
}

I believe that I am correct that application errors that are raised by the Callback event will not be caught by the Application.ThreadException? So what is the best way of insuring that the callback exceptions are handled?

I have seen on other SO posts that you can also create a handler for AppDomain.CurrentDomain.UnhandledException. Is that the best way to handle the callback exceptions?

I am just looking for best practices when using asyncronous callbacks in a winforms app.

EDIT

Nicholas…thanks for your answer. So can I put the whole callback into a try catch and then do a throw in the catch. Or do I have to explicitly check the AsyncCompletedEventArgs.error property for a non-null value.

If it IS non-null…can you tell me how to cause the callback error to bubble up to my global exception handler?

I think I would do it like this…

private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{

    if (e.Error != null)
    {
        throw e.Error;
    }

    if (DownloadHasCompleted == null) return;
    File.Copy(this.RemoteIniFilePath, this.CurrentIniFilePath, true);
    DownloadHasCompleted(this, e);
}

Seth

  • 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-28T01:15:05+00:00Added an answer on May 28, 2026 at 1:15 am

    Any exception will be passed to your DownloadFileCompleted event handler.

    This is called with a AsyncCompletedEventArgs object which has an Error property.

    You just need to check this property in your handler – it won’t be an “unhandled exception”.

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

Sidebar

Related Questions

I have a Winforms app in C# that calls calls a method asynchronously and
We have a WinForms app that runs fine on x86, but has many third-party
I have a Winforms app that has a DataGridView that is databound at runtime.
I have a winforms app that checks user credentials as it starts. If autharization
So we have a winforms app that in the task manager should anywhere from
I have a small WinForms app that utilizes a BackgroundWorker object to perform a
I have a DataGridView control in a winforms app that I'm working on. The
I have a DataGridView in a Winforms app that has about 1000 rows (unbound)
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have a winforms (VB 2008) based app that I'm developing and I want

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.