G
Guest
Hi
As we know thread pool threads are background by default. Suppose that we
change them to foreground as soon as they are started, they do some task and
exit. The problem is that the application never ends.
This is a sample:
private void MyThread(object state)
{
Thread.CurrentThread.IsBackground = false ;
}
And we have a button in a windows form application:
private void btnThread_Click(object sender, System.EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThread)) ;
}
As we see, thread pool thread does nothing and exits right away. When we
close the window theoritically the application should terminate but task
manager says opposite. Why?
As we know thread pool threads are background by default. Suppose that we
change them to foreground as soon as they are started, they do some task and
exit. The problem is that the application never ends.
This is a sample:
private void MyThread(object state)
{
Thread.CurrentThread.IsBackground = false ;
}
And we have a button in a windows form application:
private void btnThread_Click(object sender, System.EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThread)) ;
}
As we see, thread pool thread does nothing and exits right away. When we
close the window theoritically the application should terminate but task
manager says opposite. Why?