Error handling in a multithreaded environment (.NET)

Hi Experts,

      I am kind of new to .NET and multithreading in general.  I am looking for info on how to do error handling in a multithreaded environment.  I need to know the appropriate ways to:

        - stop a worker thread from the main thread (in case an error outside of the worker thread happened, or user requested it to be stopped)
        - General error handling

Thanks,
axnst2
axnst2Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
axnst2Author Commented:
I can think of ways of doing it, but what's the excepted/appropriate way of doing it?
0
 
mastooConnect With a Mentor Commented:
I don't see error handling in that example.  The important point is that exceptions can't cross thread boundaries.

As in the example, it is convenient to have each thread running in an instance of some worker class, LongProcess.  So you'll have that thread/instance catch exceptions locally, and set a member variable to indicate the error status.  When the caller detects the thread is done, it can access the member variable (via a getter).
0
 
axnst2Author Commented:
That's exactly what I was looking for.  Thanks Alex!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.