多线程在UI显示线程运行状态信息
2009-03-26 09:52
429 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
namespace WinformMultiThreading
{
public partial class Form1 : Form
{
int[] s1 = new int[5] { 1, 2, 3, 4, 5 };
string[] s2 = new string[5] { "000", "001", "002", "003", "004" };
Thread t1;
Thread t2;
public delegate void setText(string str);
setText st;
public Form1()
{
InitializeComponent();
st = new setText(this.SetTextBox1);
}
public void SetTextBox1(string str)
{
if (this.InvokeRequired)
{
this.Invoke(this.st, str);
}
else
{
this.textBox1.Text = str;
}
}
public static object o = new object();
public void F1()
{
for (int i = 0; i < 100000; i++)
{
string str ="func1:"+ i.ToString()+ "/r/n";
st(str);
Thread.Sleep(1);
}
}
public void F2()
{
for (int i = 0; i < 100000; i++)
{
string str = "Func2:"+i.ToString() + "/r/n";
st(str);
Thread.Sleep(1);
}
}
private void button1_Click(object sender, EventArgs e)
{
t1 = new Thread(new ThreadStart(F1));
t2 = new Thread(new ThreadStart(F2));
t1.Start();
t2.Start();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
namespace WinformMultiThreading
{
public partial class Form1 : Form
{
int[] s1 = new int[5] { 1, 2, 3, 4, 5 };
string[] s2 = new string[5] { "000", "001", "002", "003", "004" };
Thread t1;
Thread t2;
public delegate void setText(string str);
setText st;
public Form1()
{
InitializeComponent();
st = new setText(this.SetTextBox1);
}
public void SetTextBox1(string str)
{
if (this.InvokeRequired)
{
this.Invoke(this.st, str);
}
else
{
this.textBox1.Text = str;
}
}
public static object o = new object();
public void F1()
{
for (int i = 0; i < 100000; i++)
{
string str ="func1:"+ i.ToString()+ "/r/n";
st(str);
Thread.Sleep(1);
}
}
public void F2()
{
for (int i = 0; i < 100000; i++)
{
string str = "Func2:"+i.ToString() + "/r/n";
st(str);
Thread.Sleep(1);
}
}
private void button1_Click(object sender, EventArgs e)
{
t1 = new Thread(new ThreadStart(F1));
t2 = new Thread(new ThreadStart(F2));
t1.Start();
t2.Start();
}
}
}
相关文章推荐
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作.这种情况通常会影响到性能,甚至可能导致应用程序不响应或者使用的内存随时间不断累积
- Winform实现多线程异步更新UI(进度及状态信息)
- 多线程:显示当前程序中所用程序的线程,得到线程的信息(基础功能二)
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作.这种情况通常会影响到
- java多线程-线程运行状态-获取线程对象以及名称
- c#多线程(UI线程,控件显示更新) Invoke和BeginInvoke 区别
- JAVA之旅(十二)——Thread,run和start的特点,线程运行状态,获取线程对象和名称,多线程实例演示,使用Runnable接口
- Winform实现多线程异步更新UI(进度及状态信息)
- quotastats命令_Linux quotastats 命令用法详解:显示系统当前的磁盘配额运行状态信息
- JAVA之旅(十二)——Thread,run和start的特点,线程运行状态,获取线程对象和名称,多线程实例演示,使用Runnable接口
- Java多线程笔记一(创建运行,相关概念,JVM内存模型,线程有几种状态,死锁)
- 多线程:显示当前程序中的线程,得到线程的信息(基础功能一)
- 使用Interlocked在多线程下进行原子操作,无锁无阻塞的实现线程运行状态判断
- c#多线程(UI线程,控件显示更新) Invoke和BeginInvoke 区别
- ps 显示的运行状态信息
- 多线程显示运行状态
- 黑马程序员--04.多线程--02.【run()和start()】【线程的运行状态】【获取想成对象及其名称】
- c#多线程(UI线程,控件显示更新) Invoke和BeginInvoke 区别
- java多线程(三)_多线程练习以及线程运行状态简图
- c#中Winform实现多线程异步更新UI(进度及状态信息)