输出窗口总显示  c# 在 System.NullReferenceException 中第一次偶然出现的请教高人有办法帮忙吗

解决方案 »

  1.   


            private static ManualResetEvent ev = new ManualResetEvent(false);   //父、子线程同步           private Thread thread;
           public FrmMain(int _ip, ManualResetEvent _ev)
            {
                ip = _ip; ev = _ev;            thread = new Thread(new ThreadStart(Scan));            lock (typeof(FrmMain)) { instanceCount++; }   //同时存在的对象个数加一  
            }
      

  2.   

    Scan 在哪儿声明的?instanceCount 在哪儿声明的?这点代码看不出什么来...
      

  3.   


            private static int MaxThreadCount = 200;
            public static int instanceCount = 0;     //同时存在的对象个数        public void Open()
            {
                System.Threading.Timer timer1 = new System.Threading.Timer(new TimerCallback(OnTimer), null, 0, 200);  //200
                ev.WaitOne();
            }        private static void OnTimer(object state)
            {
                lock (typeof(FrmMain))
                {                if ((FrmMain.instanceCount < MaxThreadCount) && (startIP <= endIP))
                    {
                        while (startIP <= endIP)
                        {
                            FrmMain ck = new FrmMain(startIP, ev);
                            ck.Scan();
                            if (FrmMain.instanceCount >= MaxThreadCount) break;
                            startIP++;
                        }
                    }
                }
            }     private void Scan()
            {
                try
                {                string IP = "192.168.1." + this.ip;
                    string Return = CPing.PingResult(IP);            }
    catch{ }
             }