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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:07:28+00:00 2026-05-11T05:07:28+00:00

concurrent colleagues. I need to be able to trap an exception that might be

  • 0

concurrent colleagues.

I need to be able to trap an exception that might be thrown from a background thread.

Let the code speak for itself (it is a bad code)

 public delegate bool CheckForUpdatesHandler(Uri uri);     public class UpdatesChecker {         public event AsyncCompletedEventHandler CheckForUpdatesAsyncCompleted;         protected virtual void OnCheckForUpdatesAsyncCompleted(AsyncCompletedEventArgs args) {             if (CheckForUpdatesAsyncCompleted != null)                 CheckForUpdatesAsyncCompleted(this, args);         }          public bool CheckForUpdates(Uri ftp) {                         Thread.Sleep(1000);             throw new Exception('bla');             return true;         }                public void CheckForUpdatesAsync(Uri ftp){                         var action = new CheckForUpdatesHandler(CheckForUpdates);             var c=action.BeginInvoke(ftp, delegate(IAsyncResult state) {                 OnCheckForUpdatesAsyncCompleted(new AsyncCompletedEventArgs(null, false, null));             }, null);         }         } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:07:29+00:00Added an answer on May 11, 2026 at 5:07 am

    With Delegate.BeginInvoke, the exception will be retrieved by calling .EndInvoke – which you must do anyway to prevent a leak.

    With BackgroundWorker, it will appear on the completion event

    On a vanilla Thread, an unhandled exception will tear down the process.

    However, the simplest approach is: don’t let it throw…

        public bool CheckForUpdates(Uri ftp) {         try {             Thread.Sleep(1000);             throw new Exception('bla');             return true;         } catch (Exception ex) {             // raise an event, call a method/callback, do something         }     } 

    If you currently aren’t using EndInvoke, then perhaps switch to the above pattern and just use ThreadPool directly (rather than Delegate.BeginInvoke).

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

Sidebar

Related Questions

Using Control.Concurrent and forkIO, there are some cases that will leave the thread in
I get Concurrent Modification Exception when i try to remove an item from HashMap.
I'm designing a concurrent Java application that reads data from various medical devices available
While doing concurrent programming I need to tell the compiler/optimizer that it may not
This code will throw Concurrent Modification Exception if the list is modified in doSomething().
Quick background I have a concurrent map I used to cache some values that
How to avoid concurrent modification exception in the following code? BeanList is a list
I need to implement concurrent Dictionary because .Net does not contain concurrent implementation for
java.util.concurrent.ConcurrentLinkedQueue comes to mind, but is it really optimum for this two-thread scenario? I
If variables in Java are accessed from multiple threads, one must ensure that they

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.