寻求能在线程里运行Timer的方法。。

lihui5888 lihui5888 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
private void button1_Click(object sender, EventArgs e)
{
Thread mainthread = new Thread(main);
mainthread.Start();


}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
this.test();
timer1.Enabled = true;

}
private void main()
{
timer1.Interval = 3000;//5000毫秒,即5秒执行一次
timer1.Start();
}
private void test()
{


int n = 5;
while (n > 0)
{
Thread.Sleep(1000);
MessageBox.Show(n.ToString());
n--;
}

}

上面这段代码是想在一个线程里用Timer实现要的功能 可是程序走到timer1.start()之后不继续执行 也就是说不能激发timer1_Tick()运行 为什么哦?
...全文
评论 10
收藏 已收藏
分享
返回顶部
lihui5888
C# 111,128 成员 642,536 内容