C#多线程编程问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 01:29:31
public partial class Form1 : Form
{
public class subClass
{
int a;
public subClass(int intTemp)
{
this.a = intTemp;
}
public void Thread1()
{
//这里如何用调用getcha(int s)函数?
}
}

public Form1()
{
InitializeComponent();
}
void getcha(int s)
{
//code......
}
private void button1_Click(object sender, EventArgs e)
{
subClass a = new subClass(10);//参数10
Thread t = new Thread(new ThreadStart(a.getcha));
t

方案一:
修改void getcha(int s)为static void getcha(int s)
修改Thread t = new Thread(new ThreadStart(a.Thread1));

方案二:
//这里如何用调用getcha(int s)函数?处加入
Form1 f=new Form1();
f.getcha(this.a);
修改Thread t = new Thread(new ThreadStart(a.Thread1));

还有其它方案就不说了
这些方案在linux+mono下都可以通过,在windows +VS应该也没有问题