threaded forms, deadlocks on exit

  • Thread starter Thread starter anon
  • Start date Start date
A

anon

- realtime application has multiple forms. each form is created on a new
(gui) thread. this was supposedly for efficiency reasons, i am told. this
was done before i took this project. it was done by some java people. they
claim this is the way it is done in java.

- project worked fine in .net 1.1

- on upgrade to .net 2.0, the app does not terminate. i have to debug it
using windbg, as the deadlocks get quite bad. usually the dealocks are
caused by DLL unloads. (LdrLock or similar).

-I've even tried Thread.Abort, ExitThread, Exit etc. no luck.

- is there anything i can do to get it to exit easily.
 
anon said:
- realtime application has multiple forms. each form is created on a new
(gui) thread. this was supposedly for efficiency reasons, i am told. this
was done before i took this project. it was done by some java people. they
claim this is the way it is done in java.

- project worked fine in .net 1.1

- on upgrade to .net 2.0, the app does not terminate. i have to debug it
using windbg, as the deadlocks get quite bad. usually the dealocks are
caused by DLL unloads. (LdrLock or similar).

-I've even tried Thread.Abort, ExitThread, Exit etc. no luck.

- is there anything i can do to get it to exit easily.

Yeah, it's called rewrite the program so that it works.
 
I've used this same pattern before: creating a number of threads, and then
having a window on each thread. I've generally done it for splash screens,
but it works fine for other uses. Nothing wrong with the general pattern at
all.

The big question is where is the thread lifetime management being done?

My guess is that you're going to want to:
- On the "main" thread, signal all the forms to shutdown. May need to be a
custom windows message.
- Wait for each control thread to terminate
- Terminate the main thread.

I've also had some luck, from a "quick and dirty" perspective, in setting
the Threads to be background threads. This has eliminated a number of
shutdown issues related to rogue threads. It's an ugly hack, and spending
the time to fix the bugs is probably the better bet.
 
Back
Top