471,348 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Re: Threading problem

On Apr 11, 8:26 am, Davor Dundovic <ne...@negdje.comwrote:
The garbage collector deals with objects, not processes. The process
will exit when there are no non-background threads left running. My
guess is that your new thread isn't a background thread.

I thought since thread is an object it would be collected too.
There's an object providing a representation of the thread, but the
thread itself isn't an object. It's like a file - just because a
FileInfo may be garbage collected doesn't mean the file is deleted.
Anyway, thread was a foreground one. That was the problem.

Now I've set it to be a background and it works fine.
If I execute Thread.Abort() and Thread.Join() and then close the form
- everything is OK. No orphan processes are left hanging.
That sounds pretty odd. As Marc said, Thread.Abort should be avoided
anyway. See

How would you break from a thread that is block by a blocked call ?
If I want to shut down the process, I'd make sure that the thread is a
background thread. Otherwise, I'd either avoid blocking calls, or just
let the thread wait.
That is the situation I have.

I could use async calls but didn't want to.
Making things block gives the penalty of not always being able to shut
things down quickly, basically.
Does your other thread have an active reference to the form?

No it doesn't but it's a part of that class and since it won't
terminate (foreground thread) I suppose GC doesn't try to collect that
If it's part of that class then it does have an active reference - the
implicit "this" reference.

Jun 27 '08 #1
0 694

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
19 posts views Thread by Jane Austine | last post: by
17 posts views Thread by Andrae Muys | last post: by
2 posts views Thread by Egor Bolonev | last post: by
11 posts views Thread by Paul Sijben | last post: by
9 posts views Thread by cgwalters | last post: by
126 posts views Thread by Dann Corbit | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.