threaded forms, deadlocks on exit

threaded forms, deadlocks on exit

am 20.10.2007 22:47:46 von Hans-Peter Sauer

- 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.

Re: threaded forms, deadlocks on exit

am 21.10.2007 13:56:53 von MR. Arnold

"anon" wrote in message news:SPtSi.830$Y23.660@trndny04...
>- 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.

Re: threaded forms, deadlocks on exit

am 22.10.2007 20:25:02 von Chris Mullins

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.

--
Chris Mullins

"anon" wrote in message news:SPtSi.830$Y23.660@trndny04...
>- 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.
>
>
>