---
title: "C#多线程委托ParameterizedThreadStart应用"
author: "penua"
date: "2008-12-18T14:49:39Z"
tags: []
categories: ["编程语言"]
slug: "c-parameterizedthreadstart"
draft: false
lastmod: "2008-12-22T10:21:01Z"
id: 296536
url: "https://pinghua.iteye.com/blog/296536"
---

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");
        }
    }
}