应用程序: VioQuery.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止。异常信息: System.InvalidOperationException 堆栈: 在 System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle) 在 System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean) 在 System.Windows.Forms.Control.Invoke(System.Delegate, System.Object[]) 在 System.Windows.Forms.Control.Invoke(System.Delegate) 在 VioQuery.frmJSZInput.GetData() 在 System.Threading.ThreadHelper.ThreadStart_Context(System.Object) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 在 System.Threading.ThreadHelper.ThreadStart() 有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。这是程序运行的机器的错误日志。以下时出错界面部分代码:
   public void Button76Click(object sender, EventArgs e)
        {            //if (txtCarNo.Text == "")
            //{
            //    MessageBox.Show("车辆识别代号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
            //    return;
            //}
            aa = new frmBj();
            aa.Show();
            frmWait = new frmWait();
            Thread th = new Thread(GetData);
            th.Start();
            frmWait.ShowDialog();
        }        private void GetData()
        {
            if (!this.IsHandleCreated)
            {
                System.Threading.Thread.Sleep(500);
            }
            if (!this.IsHandleCreated)
            {
                delConfirmInput();
                frmWait.Close();
                aa.Close();
                if (Thread.CurrentThread.ThreadState != ThreadState.Aborted)
                {
                    Thread.CurrentThread.Abort();
                }
            }
            DataTable dtSurveil = null;
            try
            {
                dtSurveil = WebServiceInvoke.GetCarSurveil(CarKind.Substring(0, 2), CarNo.GetCarNo());
            }
            catch (Exception ex)
            {
                //MessageBox.Show("服务器连接失败!请联系系统管理员!!\r\n具体原因:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                frmInfo qq = new frmInfo(ex.Message);
                qq.ShowDialog();
                if (this.IsHandleCreated)
                {
                    this.Invoke(new MethodInvoker(delegate
                        {
                            //关闭相关窗体
                            delConfirmInput();
                           // this.Close();
                            frmWait.Close();
                            aa.Close();
                        })
                        );
                }
                if (Thread.CurrentThread.ThreadState != ThreadState.Aborted)
                {
                    Thread.CurrentThread.Abort();
                }
            }
            if (this.IsHandleCreated)
            {
                this.Invoke(new MethodInvoker(delegate
                {
                    //显示结果窗体,需要在此处写,用主线程生成
                    frmWait.Close();
                    aa.Close();
                    frmVioSruveilResult f = new frmVioSruveilResult(CarKind, CarNo.GetCarNo(), dtSurveil);
                    f.ShowDialog();
                    //关闭相关窗体
                    delConfirmInput();
                   // this.Close();
                })
                );
            }
        }由于使用的是交警内网,且发生错误的偶然性,我也不能调试,只能每天跑现场去看错误的信息,然后修改,这个错误出现次数不多,一天出现大概2-5次,去了几天也没找到原因,求帮忙,在线等,谢谢

解决方案 »

  1.   

    你这个新开的线程不是STA的可以对UI进行操作吗? 应该每次都会错误才对啊。 而且你在别的线程对UI进行操作的时候,不能直接操作,要用Control.invoke方法。
      

  2.   

    你这个新开的线程不是STA的可以对UI进行操作吗? 应该每次都会错误才对啊。 而且你在别的线程对UI进行操作的时候,不能直接操作,要用Control.invoke方法。
      

  3.   

    你这个新开的线程不是STA的可以对UI进行操作吗? 应该每次都会错误才对啊。 而且你在别的线程对UI进行操作的时候,不能直接操作,要用Control.invoke方法。
      

  4.   

     this.Invoke(new MethodInvoker(delegate
      {
    使用了委托操作的
      

  5.   

    正常的爆错,没做错误处理,程序就退出了(奔溃)
    最容易出错这几行
    delConfirmInput();frmVioSruveilResult f = new frmVioSruveilResult(CarKind, CarNo.GetCarNo(), dtSurveil);//这个窗体初始化做了什么东西,你自己才清楚
    你的try catch也太小气就catch一行
      

  6.   

     delConfirmInput为public MethodInvoker delConfirmInput;