未将对象引用设置到对象的实例

未将对象引用设置到对象的实例
实在是找不出问题来了  
写的这个功能是类内操作listview 显示日志的

相同的代码  我新建一个项目 随便写点操作 都没问题 可以正确运行
但是代码到这个项目里就一直报错

“未将对象引用设置到对象的实例”
我debug进去 对象updatelistview就是null  
真心无力了 
请大家帮这看看

//操作类内 namespace SocketDebugTool {     public delegate void UpdateListview(string str);        class ClientTcp     {         public event UpdateListview updatelistview;              ………………………………         /// <summary>         /// 开始         /// </summary>         public void start()         {             worker = new BackgroundWorker();               // 设置可以取消             worker.WorkerSupportsCancellation = true;             // 设置可以通告进度             //worker.WorkerReportsProgress = true;             //处理过程             worker.DoWork += new DoWorkEventHandler(doWork);             //更新控件             //worker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);             //当后台操作已完成、被取消或引发异常时发生             worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);             //go             worker.RunWorkerAsync();         }         private void doWork(object sender, DoWorkEventArgs e)         {             …………             for (int i = count; i > 0 && run; --i)             {                 ………………                     if (……)                     {                         ……                         //打日志                         string str = System.Text.Encoding.Default.GetString(recvBuf);                         loginfo.WriteLine("……:"+str);                         //                         updatelistview(str);//执行委托实例                      }                     else                    {                         ……                     }                     ……                 }                 catch (Exception ee)                 {                     ……                 }                               }             ……               //自动发送             ……         } }
//操作类内 namespace SocketDebugTool {     public delegate void UpdateListview(string str);        class ClientTcp     {         public event UpdateListview updatelistview;              ………………………………         /// <summary>         /// 开始         /// </summary>         public void start()         {             worker = new BackgroundWorker();               // 设置可以取消             worker.WorkerSupportsCancellation = true;             // 设置可以通告进度             //worker.WorkerReportsProgress = true;             //处理过程             worker.DoWork += new DoWorkEventHandler(doWork);             //更新控件             //worker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);             //当后台操作已完成、被取消或引发异常时发生             worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);             //go             worker.RunWorkerAsync();         }         private void doWork(object sender, DoWorkEventArgs e)         {             …………             for (int i = count; i > 0 && run; --i)             {                 ………………                     if (……)                     {                         ……                         //打日志                         string str = System.Text.Encoding.Default.GetString(recvBuf);                         loginfo.WriteLine("……:"+str);                         //                         updatelistview(str);//执行委托实例                      }                     else                    {                         ……                     }                     ……                 }                 catch (Exception ee)                 {                     ……                 }                               }             ……               //自动发送             ……         } }
后面又给new了一个clienttcp,前面的赋值就没有了。
clienttcp = new ClientTcp();后面加上
clienttcp.updatelistview += new UpdateListview(updatalistview);

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有