handling exceptions thrown from inside a thread

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Is there some built-in way of handling exceptions thrown inside a thread, or
do I need to pass exception conditions to a delegate (which would force me
to handle all exceptions in the thread itself)?

TIA,
Bob
 
Handle the exception in the usual way (Try/Catch). From there on in, it's
up to you what to do with it. Either yes, pass the error state back to the
client via. a delegate, or handle the error in the thread itself.
Personally, I use a delegate to tell the form what the error was and then
idle the thread (but ensuring no state was changed; in my case, by rolling
back a database transaction). The client form can then decide whether to
retry the operation (if it was cancelled due to deadlock for example) or
whether to just tell the user (a simple message box).
 
Good answer, thank you.

Maybe you can answer a few more threading questions for me?

- For cleanup, is it sufficient to set a Thread to Nothing after it's done?

- It is OK to pass objects out of the thread? (dumb question maybe but I
want to be sure)

- What's the best way to process messages coming out of a thread? I want to
queue them up, but MessageQueue doesn't look like what I need. Should I just
make my own queue class? If so I'll have to worry about enumerator
synchronization... a pointer to a 'best practice' example would be very
helpful.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top