码迷,mamicode.com
首页 > 编程语言 > 详细

带参数的多线程

时间:2014-06-30 22:00:23      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:style   color   strong   os   art   for   

1.首先定义一个线程类

public class MyThread{
private string myarg;
}
然后可以再这个线程类里面定义构造方法,这样就可以给这个线程传参数了
public MyThread(string aaa){
this.myarg=aaa;
}
然后定义线程的运行方法,在这个方法里面可以调用当前类的参数
public void run(){
do something for thread;
}
所以整个线程类就应该是这样
public class MyThread{
    private string myarg;
    public MyThread(string aaa){
        this.myarg=aaa;
    }
    public void run(){
        do something for thread;
    }
}
外部调用线程的方法
var myThread = new MyThread("canshu");
var thread = new Thread(myThread.run);
thread.Start();
这时候线程就启动了

带参数的多线程,布布扣,bubuko.com

带参数的多线程

标签:style   color   strong   os   art   for   

原文地址:http://www.cnblogs.com/qigemingzihaonan/p/3816140.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!