首页 > 代码库 > 使用线程操作刷新Winform界面
使用线程操作刷新Winform界面
主窗体中添加代码
public FrmMain() { InitializeComponent(); System.Threading.Thread thread = new System.Threading.Thread(Do_work); thread.IsBackground = true; thread.Start(); } private void Do_work() { while (true) { //将sleep和无限循环放在等待异步的外面 System.Threading.Thread.Sleep(5000); System.Windows.Forms.Application.DoEvents(); ThreadFuntion(); } } private void ThreadFuntion() { if (this.label_State.InvokeRequired) { //1 通常方法:将代理绑定到方法 FlushClient fc = new FlushClient(ThreadFuntion); this.BeginInvoke(fc);//通过代理调用刷新方法 } else { label_State.Text = "程序已经运行5秒钟了"; } }
使用线程操作刷新Winform界面
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。