线程多参数的传递方法,除了类还有什么方法?
如题,哪位大神给出代码参考学习,
不要类的方法
在线等待........
------解决方案--------------------用struct也可以。
------解决方案--------------------private void ThreadMethodWithParameter(object obj)
{
string[] arr = obj as string[];
if (arr != null)
{
}
}
调用
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadMethodWithParameter));
thread.Start(new string[] { "a", "b" });
给了你一个数组的例子
自己研究下吧
------解决方案--------------------匿名方法,闭包
------解决方案--------------------1:
int a = 1; int b = 0;
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Th_proc));
th.Start(new object[] { a, b });
private void Th_proc(object args)
{
object[] objs = args as object[];
int aa = (int)objs[0];
int bb = (int)objs[1];
//...
}
2:
int a = 1; int b = 0;
th = new System.Threading.Thread((System.Threading.ThreadStart)delegate()