M
Mike Brown
I have created threads in a low level part of my application. When the
application goes to close I use the currentProcess.Threads to get the
current threads associated with my application. The problem is that I can't
identify the threads that were created by lower level parts of the program.
I cannot access the original thread or its name. I can only get the ID from
ProcessThread and when I create the thread I don't have an ID.
What is the relationship between ProcessThread and Thread. How can I get
the thread information from ProcessThread?
OR
How can I determine which threads are mine?
Thanks,
Mike
See Code Below:
Here is the thread creation code:
EMailSender emailSender = new EMailSender(emailSendInfo, emailAddresses);
System.Threading.ThreadStart threadStart = new
System.Threading.ThreadStart(emailSender.Send);
System.Threading.Thread threadMail = new
System.Threading.Thread(threadStart);
threadMail.Name = "Workflow E-Mail Notification Process";
threadMail.Start();
Here is the thread code when the application closes.
private ProcessThreadCollection GetRunningThreads()
{
Process processCurrent = Process.GetCurrentProcess();
if (processCurrent == null)
{
return null;
}
return processCurrent.Threads;
}
private void DisplayThreadsRunning()
{
ProcessThreadCollection processThreads = GetRunningThreads();
if (processThreads != null)
{
string message = string.Format("blah blah cannot be closed, there are {0}
Designer threads still running and must complete first.\n\nThreads
Running:\n", processThreads.Count);
foreach (ProcessThread processThread in processThreads)
{
somehow assemble meaningful thread information like the name for display.
I also get other threads used by system (clr probably created). I can't
distinguish anything meaningful here. processThread.ID doesn't help me
unless I can query the thread with it some how.
}
display running thread info including descriptive names to the user.
}
}
application goes to close I use the currentProcess.Threads to get the
current threads associated with my application. The problem is that I can't
identify the threads that were created by lower level parts of the program.
I cannot access the original thread or its name. I can only get the ID from
ProcessThread and when I create the thread I don't have an ID.
What is the relationship between ProcessThread and Thread. How can I get
the thread information from ProcessThread?
OR
How can I determine which threads are mine?
Thanks,
Mike
See Code Below:
Here is the thread creation code:
EMailSender emailSender = new EMailSender(emailSendInfo, emailAddresses);
System.Threading.ThreadStart threadStart = new
System.Threading.ThreadStart(emailSender.Send);
System.Threading.Thread threadMail = new
System.Threading.Thread(threadStart);
threadMail.Name = "Workflow E-Mail Notification Process";
threadMail.Start();
Here is the thread code when the application closes.
private ProcessThreadCollection GetRunningThreads()
{
Process processCurrent = Process.GetCurrentProcess();
if (processCurrent == null)
{
return null;
}
return processCurrent.Threads;
}
private void DisplayThreadsRunning()
{
ProcessThreadCollection processThreads = GetRunningThreads();
if (processThreads != null)
{
string message = string.Format("blah blah cannot be closed, there are {0}
Designer threads still running and must complete first.\n\nThreads
Running:\n", processThreads.Count);
foreach (ProcessThread processThread in processThreads)
{
somehow assemble meaningful thread information like the name for display.
I also get other threads used by system (clr probably created). I can't
distinguish anything meaningful here. processThread.ID doesn't help me
unless I can query the thread with it some how.
}
display running thread info including descriptive names to the user.
}
}