循环创建10个线程,每个线程调用一个方法,然后每个线程再相隔10秒一直循环执行,并统计每个线程执行次数。
请问各位大侠,这个代码怎么实现?

解决方案 »

  1.   

    Thread[] tr = new Thread[10];
    Count[] trCount = new Count[10];class Count
    {
        private int _count = 0;
        public int Count
        {
            get { return _count; }
        }
        
        public void Count()
        {
            while(true)
            {
                _cout++;
                Thread.Sleep(10000);
            }
        }
    }for(int i=0;i<tr.length;i++)
    {
        trCount[i] = new Count();
        tr[i] = new Thread(new ThreadStart(trCount[i].Count));
        tr[i].Start();    
    }
      

  2.   

    1楼的应该可以。你要返回值,只要调用tr[i].Count就可以啊。