How to catch exception in the main thread if the exception occurs in the secondary thread?
The code snippet for the scenario is given below:
private void button1_Click(object sender, EventArgs e)
{
try
{
Thread th1 = new Thread(new ThreadStart(Test));
th1.Start();
}
catch (Exception)
{
}
}
void Test()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
if (i == 2)
throw new MyException();
}
}