Thread.Abort is delivered to the thread when it is executing managed code.
If the thread makes a call to unmanaged code then the delivery of the
Thread.Abort is delayed until the thread returns to managed code. For v1.1
if a thread is "stuck" in unmanaged code then even unloading an appdomain
will fail as the runtime will not be able to unwind the thread from
unmanaged code - the unload will timeout and the appdomain will remain
loaded in memory and you will get an AppdomainUnloadException. I haven't
tried this yet in v2.0 so I can't verify if it behaves differently under
2.0.
When the application itself is being shutdown all threads are suspended;
the shutdown procedure does not attempt to unwind the threads so the
shutdown will succeed even if a thread is "stuck" somewhere. During shutdown
it does not matter if a thread is marked as background or not.
In the 1.1 runtime if you have an app that must call out to unmanaged code
and if you cannot be sure that the unmanaged code will always return from
the call then your options are limited. About the only surefire way to
ensure that the resources get released is to actually exit the application.
There have been some improvements to this in the 2.0 runtime but I haven't
worked with that version enough yet to know its limitations. There is a
concept called an appdomain rude unload which may provide the ability to
unload an appdomain even if a thread remains stuck but I am unsure of
exactly what its capabilities are; I need to do some reading on this.
"Artem" <u20565@uwe> wrote in message news:5e5e074e0efc0@uwe...
When I use the method Thread.Abort, it only sends a request of aborting to
OS
to stop a thread. The thread itself isn't killed and allocated resources
aren't released. I tried to run that thread inside of a domain, specially
created for it, but the domain can't be unloaded, 'till there are some
not-
stopped threads.
Please, tell me are there any ways to immediately stop a thread or unload
a
domain?
Thanks beforehand!