Reputation: 161
Well, I have a main thread and one more additional. Now I need to check additional thread before closing the program and if it's running - ask 'terminate it or not', else - just close the app.
1st edit:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (calculation.IsAlive)
{
e.Cancel = true;
}
else
{
//
}
}
How to close app. in 'else' part? I think it's so easy but I can not find out it))
Upvotes: 0
Views: 147
Reputation: 5140
Thread.IsAlive
flag will do the trick.
var t=new Thread(() => { });
if (t.IsAlive)
{
//thread is still alive
//true if this thread has been started and has not terminated normally or aborted;
}
else
{
//not alive
//otherwise, false.
}
Upvotes: 2