Thread th = new Thread(test)
th.IsBackground = true;
th.Start();
创建线程对象,传入需要线程执行的函数名
标记线程准备就绪,可以随时被执行
进行设置
设置为后台程序
线程间操作无效,在form_load中增加
Control.CheckForIlegalCrossThreadCall = False
c. 当点击关闭窗体的时候,判断新线程是否为null,如果部位null, 手动关闭
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{if(th!= null)
{// 结束这个线程
th.Abort()
}
}