如何通过c#.net中的线程将值传递给另一个函数中的函数 [英] how to pass value to the function which is in another fuction through thread in c#.net

查看:106
本文介绍了如何通过c#.net中的线程将值传递给另一个函数中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过线程将值传递给函数...以下是没有线程的原始代码..



private void btnsearch_Click(object sender,EventArgs e )

{

SearchRecord(QuerySearch);

}



以下是代码我正在尝试..使用线程..



private void btnsearch_Click(object sender,EventArgs e)

{

Thread Proceso1 = new Thread(new ThreadStart(load));

Proceso1.Start();



Thread Proceso2 = new线程(新的ThreadStart(loadTable));

Proceso2.Start();



}



private void loadTable(int QuerySearch)

{



SearchRecord(QuerySearch);





}



< br $>


public void load()

{



if(pictureBox1.InvokeRequired )

{

MethodInvoker assign = new MethodInvoker(load);

pictureBox1.Invoke(assign);



}

其他

{

pictureBox1.Visible = true;

< br $>
}

Thread.Sleep(100);

}







plz帮我通过主线程将querysearch的值传递给函数

i want to pass value to the function through thread... following is the original code without thread..

private void btnsearch_Click(object sender, EventArgs e)
{
SearchRecord(QuerySearch);
}

following is the code i m trying.. using thread..

private void btnsearch_Click(object sender, EventArgs e)
{
Thread Proceso1 = new Thread(new ThreadStart(load));
Proceso1.Start();

Thread Proceso2 = new Thread(new ThreadStart(loadTable ));
Proceso2.Start();

}

private void loadTable(int QuerySearch)
{

SearchRecord(QuerySearch);


}



public void load()
{

if (pictureBox1.InvokeRequired)
{
MethodInvoker assign = new MethodInvoker(load);
pictureBox1.Invoke(assign);

}
else
{
pictureBox1.Visible = true;

}
Thread.Sleep(100);
}



plz help me to pass value of querysearch through main thread to function

推荐答案

你传入的对象Thread构造函数(新的Thread(Object)用于将数据传递给线程。在线程上调用Start方法之前的某个时刻,使用其属性传入数据。
The Object that you pass into the Thread constructor (new Thread(Object) is intended for passing data to the thread. At some point before you call the Start method on the threads, use its properties to pass in your data.


尝试:

Try:
Thread myThread = new Thread(MethodName);
myThread.Start(ParameterObject);



所以在你的情况下它将是:


So in your case it would be:

Thread Proceso2 = new Thread(loadTable);
Proceso2.Start(QuerySearch);


这篇关于如何通过c#.net中的线程将值传递给另一个函数中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆