for(int i = 0;i<6;i++)
{
Thread thread = new Thread(new ThreadStart(Filter));
thread.Name = Convert.ToString(i);
thread.Start();
}
private void Filter()
{
DateTime startTime = DateTime.Now;
try
// {
// while(true)
// {
int j = 0;
for(int i=0;i<al.Count;i++)
{
lock(typeof(Thread))
{
if(isOK(al[i].ToString()))
{
j = j+1;
//MessageBox.Show(al[i].ToString()+"非法!");
}
}
}
// Thread.Sleep(1);
// }
//MessageBox.Show("a");
Thread.CurrentThread.Abort();
}
我希望多个线程同时执行Filter()需要怎么写啊,
{
Thread thread = new Thread(new ThreadStart(Filter));
thread.Name = Convert.ToString(i);
thread.Start();
}
private void Filter()
{
DateTime startTime = DateTime.Now;
try
// {
// while(true)
// {
int j = 0;
for(int i=0;i<al.Count;i++)
{
lock(typeof(Thread))
{
if(isOK(al[i].ToString()))
{
j = j+1;
//MessageBox.Show(al[i].ToString()+"非法!");
}
}
}
// Thread.Sleep(1);
// }
//MessageBox.Show("a");
Thread.CurrentThread.Abort();
}
我希望多个线程同时执行Filter()需要怎么写啊,
每个线程都执行一遍Filter()
Filter()是个循环过滤
现在的问题的是开一个线程就要循环一个 我就想让多线程就循环一个
lock就对了!