是你这个判断的问题
if(r.IsOK)
{
把它去了试试,就没有问题了

解决方案 »

  1.   

    using System;
    using System.Threading;
    using System.Collections;
    class Class1
    {    [STAThread]
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList();
            list.Add(5);
            list.Add(6);
            list.Add(7);
            ManualResetEvent allDone = new ManualResetEvent(false);
            for (int i = 0; i < list.Count; i++)
            {
                int ii = (int)list[i];
                Console.WriteLine("from" + ii);
                ForRun r = new ForRun(ii);            allDone.Reset();
                Console.WriteLine("start");
                Thread thread = new Thread(new ParameterizedThreadStart(r.run1));
               
                thread.Start(allDone);            
                allDone.WaitOne();
                if (r.IsOK)
                {
                    r.IsOK = false;
                    Console.WriteLine("sleep");
                    Thread.Sleep(5000);            }
            }
            Console.Read();
        }}
    public class ForRun
    {    private bool isOK = false;
        private int i = 0;    public bool IsOK
        {
            get { return isOK; }
            set { isOK = value; }    }
        public ForRun(int i)
        {
            this.i = i;
        }    public void run1(object o)
        {
            lock (this)
            {            for (int ii = 0; ii <= this.i; ii++)
                {
                    Console.WriteLine(ii);
                    if (ii == i)
                        this.isOK = true;            }        }
            ((ManualResetEvent)o).Set();    }
    }
      

  2.   

    很感谢楼上的:但是我的环境是.net 1.1的
      

  3.   

    1.1 中没有 ManualResetEvent 吗?