Thread myThread; // New a thread
// make the thread to work.
private void button2_Click(object sender, EventArgs e)
{
myThread = new Thread(new ThreadStart(Add));
myThread.Start();
}
// When close the program, and close the Thread
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
myThread.Abort();
myThread.Join();
}
catch
{
}
}