调试显示,执行到这一句时:
               DisplayLog dFunc = new DisplayLog(SetTxtLog);
                this.Invoke(dFunc, new object[] { s });
报错:
“在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke”

解决方案 »

  1.   

    是的,但是要怎么解决呢?
    我把代码改成:
    if (txtLog.IsHandleCreated)
    {
       DisplayLog dFunc = new DisplayLog(SetTxtLog);
       if ((!this.IsDisposed) && (this!=null) && (this.IsHandleCreated) && (!txtLog.IsDisposed))
                  this.Invoke(dFunc, new object[] { s });
    }错误提示变成了:
    无法访问已释放的对象。
    对象名:“FrmMain”。
      

  2.   

    增加一个this.IsDisposed || !this.IsCreateHandle
               return;