求从线程执行一个很长的Thread.Sleep()UI线程又不卡死的办法

a091003040421 a091003040421 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
namespace WindowsFormsApplication1
{


public partial class Form1 : Form
{
private delegate void MyDelegate();
int num = 0;
Thread t1;
public Form1()
{
InitializeComponent();

}
private void button1_Click(object sender, EventArgs e)
{
t1 = new Thread(SetText);
t1.IsBackground = true;
t1.Start();
}

private void SetText()
{
MyDelegate d1 = StartDelegate;
while (true)
{
textBox1.Invoke(d1);
}
}
void StartDelegate()
{
//textBox1.Text = num++.ToString();
Thread.Sleep(10000);
}

private void button2_Click(object sender, EventArgs e)
{
t1.Suspend();
}
}
}
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
a091003040421
C# 111,129 成员 642,540 内容