Solved

Error handling in a multithreaded environment (.NET)

Posted on 2006-06-15
4
229 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:axnst2
  • 2
4 Comments
 

Author Comment

by:axnst2
ID: 16911165
I can think of ways of doing it, but what's the excepted/appropriate way of doing it?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 300 total points
ID: 16911339
0
 
LVL 21

Assisted Solution

by:mastoo
mastoo earned 200 total points
ID: 16911443
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
 

Author Comment

by:axnst2
ID: 16911452
That's exactly what I was looking for.  Thanks Alex!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question