ITeye博客

C#多线程委托ParameterizedThreadStart应用

penua · 2008-12-18 14:49 · DotNet应用 · 编程语言 · Markdown

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;

namespace threadCtrTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //带参数的线程函数,参数必须为object类型 public void txtShow(object name) { textBox1.Text = Convert.ToString(name);//可以根据需要转换类型 } private void button1_Click(object sender, EventArgs e) { //这一属性设置为false,则可以非安全的跨线程操作UI控件。 Control.CheckForIllegalCrossThreadCalls = false; //实例化一个线程,该线程的代理指向一个带参数的线程函数 Thread myt = new Thread(new ParameterizedThreadStart(txtShow)); //这里传入object类型参数 myt.Start("jamT"); } } }

评论(1)

  1. #1 楼 · mooniscrazy · 2009-01-16 14:28

    这个程序运行过吗?要出错吧。

评论功能维护中,当前仅展示历史评论。