WinForm多线程
来源:互联网 发布:数控机床怎么存入编程 编辑:程序博客网 时间:2024/05/22 06:55
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApplication1.AppClass;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private delegate void FlushClient(); //代理
Thread thread = null;
int counter = 0;
private void button1_Click(object sender, EventArgs e)
{
//this.textBox1.Clear();
button1.Enabled = false;
thread = new Thread(CrossThreadFlush);
thread.IsBackground = true;
thread.Start();
}
private void CrossThreadFlush()
{
while (true)
{
//将sleep和无限循环放在等待异步的外面
Thread.Sleep(1000);
ThreadFunction();
}
}
private void ThreadFunction()
{
if (this.textBox1.InvokeRequired)//等待异步
{
FlushClient fc = new FlushClient(ThreadFunction);
this.Invoke(fc); //通过代理调用刷新方法
}
else
{
counter += 1;
this.textBox1.Text += counter.ToString()+"\n\t";
this.textBox1.Text += System.DateTime.Now.ToString() + "\n\t";
}
}
private void button2_Click(object sender, EventArgs e)
{
thread.Suspend();
button1.Enabled = true;
}
}
}
- WinForm多线程
- WinForm多线程
- Winform多线程
- winform多线程
- Winform 程序中的多线程.
- Winform的多线程问题
- 多线程存取WinForm控件
- C# WinForm多线程
- WinForm多线程学习文档
- winform 多线程定时执行
- WinForm多线程学习文档
- C# WinForm 多线程 基类
- WinForm中多线程问题?
- Winform 多线程 文件操作
- c# winform 实现多线程
- WinForm 多线程操作UI
- Winform 多线程查询数据
- 在多线程中调用WinForm
- cocos2d-x SimpleGame(3)如何发射子弹
- volatile语义及线程安全singleton模式探讨
- SVN使用手册大全(史上最全)
- C#委托
- Huffman树与Huffman编码
- WinForm多线程
- YII-视图- kindeditor扩展
- 简单Linux服务器的基本配置
- 2013.1.10
- 重命名 delphi 编译输出文件名
- Java 正则表达式详解
- 技术从此开始
- 从键盘上输入两个整数_由用户回答它们的和_差_积_商和取余运算结果_并统计出正确答案的个数
- Ubuntu Virtualbox桥接 配置