C#多线程数组启动终止和多参传递操作

最近做点小活,非要求用C#,OK,用就用吧,还非要用多线程,OK用就用吧,还非要用多线程数组,也OK

,还非要用多参,...
 
我快受不鸟你了,
 
总算完活了
 
把我痛苦的经历凝练了一下,供挖坟使用,
 
挖坟呀,要唱忐忑的。啊移呀哟!!!!!!

public class parm
{
	public string name;
	public int ckl;
}
public static Thread[] everun;
public static parm temp;
void Button1Click(object sender, EventArgs e)
{
	if(button1.Text =="开始")
	{
		button1.Text ="停止";
		//声明线程数组共有几个
		everun=new Thread[5];
		temp=new parm();
		for(int i=0;i<5;i++)
		{
			//带参的线程声明
			everun[i]=new Thread(new ParameterizedThreadStart(fun));
			temp.name="name"+i.ToString () ;
			temp.ckl=i;
			//声明后台运行
			everun[i].IsBackground = true;
			//MessageBox.Show(temp[tt].name.ToString());
			everun[i].Start(temp);
		}
	}
	else
	{
		
		for(int i=0;i<everun.Length ;i++)
		{
			if(everun[i]!= null&&everun [i].IsAlive==true )
			{
				//try
				//{
				//MessageBox.Show("终止");
				everun[i].Abort();
				//}
				//catch {;}

			}
		}
		
		
		button1.Text ="开始";
	}
}
public void fun(object obj)
{
	parm t= obj as parm;
	//MessageBox.Show(t.name.ToString()+":"+t.ckl.ToString ());
	while (true )
	{
		Thread .Sleep (5000);
	}
}


 

你可能感兴趣的:(C#多线程数组启动终止和多参传递操作)