c# 多线程传递参数Demo (一个参数传递)
2010-02-05 14:10
525 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace XianChen
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
Thread t1, t2;
private void button1_Click(object sender, EventArgs e)
{
int i = 100;
t1 = new Thread(this.th1);
t1.Start(i);
}
private void button2_Click(object sender, EventArgs e)
{
t1.Suspend();
}
private void button7_Click(object sender, EventArgs e)
{
t1.Resume();
}
private void button3_Click(object sender, EventArgs e)
{
t1.Abort();
}
private void button4_Click(object sender, EventArgs e)
{
int i = 200;
t2 = new Thread(this.th2);
t2.Start(i);
}
private void button5_Click(object sender, EventArgs e)
{
t2.Suspend();
}
private void button8_Click(object sender, EventArgs e)
{
t2.Resume();
}
private void button6_Click(object sender, EventArgs e)
{
t2.Abort();
}
private delegate void weituo(object tmp);
private void th1(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js1),tmp);
Thread.Sleep(1000);
}
else
{
js1(tmp);
}
}
}
private void th2(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js2),tmp);
Thread.Sleep(1000);
}
else
{
js2(tmp);
}
}
}
private void js1(object tmp)
{
listBox1.Items.Add("这里是线程 1 在传递参数:"+tmp);
}
private void js2(object tmp)
{
listBox1.Items.Add("这里是线程 2 在传递参数:" + tmp);
}
}
}
本文出自 “知识就是财富” 博客,请务必保留此出处http://lovefly.blog.51cto.com/914912/274625
相关文章推荐
- c# 多线程传递多参数Demo
- C# 多线程传递参数的三种方式
- C# 多线程 线程中参数传递
- c#参数传递使用中的一个坑,值传递与引用传递
- (转)一步一步学习C#中的多线程 --- 1、初识线程(2)--给线程传递参数
- c# 多线程的一个小Demo
- .NET多线程编程(7)——C#多线程编程传递参数解决方案
- C# 中传递多个参数给多线程
- C# 多线程 参数传递
- C# 使用多线程如何传递两个以上参数的实现方法(附示例) 推荐
- c# 多线程传递参数之解决方案
- C#从一个窗体传递参数到另一个窗体的链接
- 【C#Winform】一个多线程扫描本地磁盘目录文件个数的Demo
- C# 给多线程传递参数
- Win32 API 多线程编程——一个简单实例(含消息参数传递)
- C# 多线程 参数传递
- 一步一步学习C#中的多线程 --- 1、初识线程(2)--给线程传递参数
- c# 多线程传递参数以及任务
- C# 给多线程传递参数的三种方式
- C# 给多线程传递参数的三种方式