473,241 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to manually abort a thread on unload a domain?

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!
Apr 6 '06 #1
2 2177
> The thread itself isn't killed and allocated resources aren't released.
...
Please, tell me are there any ways to immediately stop a thread or unload a
domain?


If you want to stop the threads because the app is stopping, then you can
set the thread's IsBackground=true. When the app stops, the threads will
stop abruptly. If your threads can stand that (eg a partially updated
file?), then all is well.

If you want the app to continue but have the threads stop and clean up their
resources, then IMO there is no good built in way. I am sure others will
disagree, but at least in .net 2003, I will not be persuaded. I have had
some nasty experiences in this area, and O'Reilly in ".NET Gotchas" has an
entire chapter devoted to threading issues.

I do this function with the following home grown mechanism. I have a
program wide shared integer variable that is thread protected by the
Threading.Interlocked functions. Threads get a copy of this variable when
they start. When I want to cancel threads, I increment the variable.
Threads periodically compare their copy with the global, and they quit
gracefully when they are different. The main advantage of this design (over
say a global boolean) is that while some threads are cancelling, others can
be started, and there is no interference.
Apr 6 '06 #2
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!

Apr 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephan Steiner | last post by:
Hi I'm having some weird threading issues.. almost at random, if I dare change a line of my code, the shutdown sequence gets messed up. I'm using a thread to receive data from the network, that...
1
by: Luis Pinho | last post by:
Hi There, I've got a server that is waiting for requests, these request correspond to calls to objects that are specified in assemblies stored in the GAC. To do this, I use reflection to call...
6
by: Wal Turner | last post by:
Hi there. There are various snippets on forums regarding issues with AppDomain.Unload and how it just doesnt work. Fortunately, I got it working with the base case, after much fiddling. Consider...
13
by: Andy Fish | last post by:
Hi, I am using COM interop to invoke MS word from my .net app. If word pops up a dialog box, my thread obviously hangs until the dialog is answered. Here's the problem: because the app is...
6
by: mflanagan | last post by:
I have unmanaged C++ program that will load a managed C++ dll and then call a function in that dll. The managed C++ routine will call some C# routines. The unmanaged C++ main program will make...
5
by: [Yosi] | last post by:
Why I can't abot a susspended thread. Who can terminat a thread imediatly without consider to its stat or execution?
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
5
by: Alan T | last post by:
I will do several things in my thread: Copy a file to a location Update database record Read the file content Write the content to a log file If I call Thread.Abort(), it may be possible to...
6
by: mehdi | last post by:
Hi folks, You know, the Thread class has got a method named Abort which according to the msdn: "Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.