Form timer无法停止线程
我想通过timer实现定时启动任务的工作,大致代码如下,但是在执行后发现文本输出不会间隔两秒输出,停止该线程也不行
private void timer2_Tick(object sender, EventArgs e)
{
string str_start = this.timePick_start.Text;
if (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Equals(str_start))
{
thre = new Thread(getclik);
thre.IsBackground = true;
thre.Start();
}
}
void getclik()
{
while(true)
{
Console.WriteLine("aaaaa");
Thread.Sleep(2000);
}
}