G
Guest
Hello,
I've got an issue where a process in a third party application has a dll
which while exiting sort of freezes and runs away with processor cycles.
i've written a block of code so that I can drill down into the process, and
get the offending Thread's ID (since the only ones that will have the issue
have higher User processor Time).
But, I can't figure out how to have my .Net app 'kill' or 'suspend' a Thread
based on the Id I have gotten. I see a lot of samples on how to do this with
treads your application starts itself, but nothing 'external' to the app.
Anyone able to lend a hand?
Here's my base routine.....
private static void DoSuspendThread(string processName)
{
// Suspend thread
Console.WriteLine("Passed " + processName);
try
{
Process[] myProcesses = Process.GetProcessesByName(processName);
foreach (Process myProcess in myProcesses)
{
foreach (ProcessThread t in myProcess.Threads)
{
// info += myProcess.ProcessName + " " + t.Id + " " +
t.UserProcessorTime + Environment.NewLine;
TimeSpan time = new TimeSpan(0, 1, 0, 0, 0);
if ((t.UserProcessorTime > time) && (t.ThreadState ==
System.Threading.ThreadState.Running))
{
// Kill or suspend here
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception " + e.Message);
}
}
I've got an issue where a process in a third party application has a dll
which while exiting sort of freezes and runs away with processor cycles.
i've written a block of code so that I can drill down into the process, and
get the offending Thread's ID (since the only ones that will have the issue
have higher User processor Time).
But, I can't figure out how to have my .Net app 'kill' or 'suspend' a Thread
based on the Id I have gotten. I see a lot of samples on how to do this with
treads your application starts itself, but nothing 'external' to the app.
Anyone able to lend a hand?
Here's my base routine.....
private static void DoSuspendThread(string processName)
{
// Suspend thread
Console.WriteLine("Passed " + processName);
try
{
Process[] myProcesses = Process.GetProcessesByName(processName);
foreach (Process myProcess in myProcesses)
{
foreach (ProcessThread t in myProcess.Threads)
{
// info += myProcess.ProcessName + " " + t.Id + " " +
t.UserProcessorTime + Environment.NewLine;
TimeSpan time = new TimeSpan(0, 1, 0, 0, 0);
if ((t.UserProcessorTime > time) && (t.ThreadState ==
System.Threading.ThreadState.Running))
{
// Kill or suspend here
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception " + e.Message);
}
}