问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Threading;namespacemulthread{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){inti;infor.node[]tem=newinfor.node[3];for(i=0;i<3;i++){tem[i].data=2*i;}Class1ca=newClass1();//for(i=0;i<3;i++)//{ThreadPool.QueueUserWorkItem(newWaitCallback(ca.func),newinfor(tem,3));ThreadPool.QueueUserWorkItem(newWaitCallback(ca.func),newobject//}}}publicclassClass1{publicinttemp;publicstringstr;publicvoidfunc(objectstate){for(intt=0;t<3;t++){MessageBox.Show(((infor.node)state).data.ToString());//MessageBox.Show(t.ToString());}}}publicclassinfor{publicstructnode{publicintdata;publicstringstr;}publicinfor(node[]t,intn){node[]nd=newnode[n];for(inti=0;i<n;i++){nd[i]=t[i];}}}}不知道哪里错了请高人指点
解决方案
解决方案二:
ThreadPool.QueueUserWorkItem(newWaitCallback(ca.func),newobject