Close program, and close thread

 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
            {
            }
        }

posted @ 2009-10-23 11:45  greencolor  阅读(304)  评论(0编辑  收藏  举报