在表单初始化时,我声明了timer
(此计时器的period
值为1分钟)
public Form3()
{
InitializeComponent();
timer_1m = new System.Threading.Timer(new TimerCallback(timerElapsed_test), null, 0, _1min);
}
每60秒,我开始一个新的线程来做某事。
void timerElapsed_test(object sender) //timer period: 60 seconds
{
Thread thread = new Thread(new ParameterizedThreadStart(Do));
thread.Start(null);
}
void Do(object o)
{
label1.Text = "triggerd at " + DateTime.Now.ToString("HH:mm:ss"); //assume this is a task needs to take a lot of time
//Do I need to close this thread here? and how?
}
我是否需要手动close
线程?如果是,怎么样?
答案 0 :(得分:1)
就像Idle_Mind所说,一旦线程“退出”,你就可以了。
线程例程完成后,垃圾回收将处理它。