I started a thread inside a label click event. The thread did its job. I even got the last message box inside the thread. I want to execute some more instructions inside the label click event after finishing the thread. So I used an if
statement with IsAlive
property of the thread. Seems like thread's IsAlive
property value is always true
. How? How to make sure that all thread gonna end when I close the application or is it gonna end naturally when I close the application?
private void lbl_Calc_Click(object sender, EventArgs e)
{
Label label = (Label)sender;
//new thread to do the calc
Thread t = new Thread(() => ThreadedMethodForCalc(label));
t.Start();
//checking the IsAlive property
//but doesn't work
if (t.IsAlive==false)
{
MessageBox.Show("please enter the data");
//more instruction here
}
}
private void ThreadedMethodForCalc(Label label)
{
//calculation. not shown
MessageBox.Show("end of thread"); //executed
return;
}