Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate All Threads

Status
Not open for further replies.

stevensteven

Programmer
Jan 5, 2004
108
CA
Hello,

New treads have been started in my program from a file I cannot modify.

Is there a way to terminate all threads?

Steven
 
I think you should try to use the TerminateThread() API :
Code:
[DllImport("kernel32.dll")]
private static extern bool TerminateThread (Int32 id, Int32 dwexit);
-retrieve the Process objects that started those threads:
Process[] pArray = Process.GetProcessesByName("myexename");
-iterate through process array and retrieve the ThreadProcess collection of threads for each process and try to terminate
Code:
foreach (Procees p in pArray)
{
	ProcessThreadCollection ptc = p.Threads;
	foreach (ProcessThread pt in ptc)
	{
    		TerminateThread (pt.Id,0);
    	}
}
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top