On Apr 11, 8:26 am, Davor Dundovic <ne...@negdje.c omwrote:
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.
Right.
>
>
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.
Making things block gives the penalty of not always being able to shut
things down quickly, basically.
>
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
class.
If it's part of that class then it does have an active reference - the
implicit "this" reference.
Jon
<sk...@pobox.co mwrote:
>
I thought since thread is an object it would be collected too.
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.
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.
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.
>
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.
- everything is OK. No orphan processes are left hanging.
That sounds pretty odd. As Marc said, Thread.Abort should be avoided
anyway. See
anyway. See
How would you break from a thread that is block by a blocked call ?
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.
>
I could use async calls but didn't want to.
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
class.
implicit "this" reference.
Jon