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.WriteLi ne("Passed " + processName);
try
{
Process[] myProcesses = Process.GetProc essesByName(pro cessName);
foreach (Process myProcess in myProcesses)
{
foreach (ProcessThread t in myProcess.Threa ds)
{
// info += myProcess.Proce ssName + " " + t.Id + " " +
t.UserProcessor Time + Environment.New Line;
TimeSpan time = new TimeSpan(0, 1, 0, 0, 0);
if ((t.UserProcess orTime > time) && (t.ThreadState ==
System.Threadin g.ThreadState.R unning))
{
// Kill or suspend here
}
}
}
}
catch (Exception e)
{
Console.WriteLi ne("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.WriteLi ne("Passed " + processName);
try
{
Process[] myProcesses = Process.GetProc essesByName(pro cessName);
foreach (Process myProcess in myProcesses)
{
foreach (ProcessThread t in myProcess.Threa ds)
{
// info += myProcess.Proce ssName + " " + t.Id + " " +
t.UserProcessor Time + Environment.New Line;
TimeSpan time = new TimeSpan(0, 1, 0, 0, 0);
if ((t.UserProcess orTime > time) && (t.ThreadState ==
System.Threadin g.ThreadState.R unning))
{
// Kill or suspend here
}
}
}
}
catch (Exception e)
{
Console.WriteLi ne("Exception " + e.Message);
}
}
Comment