I am developing one small excel application, in that i am using 3 threads reading some function. Its not necessary that all threads are invoked to read particular function, based on checkbox selection , particular thread will run.
Threads i defined under global part as listed below.
Thread Run_thread = null, Run_thread1 = null, Run_thread2 = null;
/* calling of threads based on checkbox selection*/
if ((checkBox1.Checked == true) && (textBox2.Text != ""))
{
Run_thread = new Thread(() => READ_MAPPING_FILE_PATHS(textBox2.Text, 5, 15));
Run_thread.Start();
check++;
}
if ((checkBox2.Checked == true) && (textBox5.Text != ""))
{
Run_thread1 = new Thread(() => READ_MAPPING_FILE_PATHS(textBox5.Text, 7, 9));
Run_thread1.Start();
check++;
}
if ((checkBox3.Checked == true) && (textBox6.Text != ""))
{
Run_thread2 = new Thread(() => READ_MAPPING_FILE_PATHS(textBox6.Text, 5, 15));
Run_thread2.Start();
check++;
}
now if user selects checkbox 1 and checkbox2 then Run_thread1 and Run_thread will be in IsAlive state and Run_thread2 will have null;
now checking thread is alive or not
if (!(Run_thread.IsAlive || Run_thread1.IsAlive || Run_thread2.IsAlive))
{
//do something
}
else
{
//message thread are in running mode.
}
in above check error is coming when Run_thread2 is checked for status
"Object reference not set to an instance of an object."
can some one help me in fixing this issue. I am new to thread.