- 爱易网页
- 
                            C#教程
- C#线程中操作出现错误,希望有人能帮忙看下,弄很久了 
日期:2014-05-18  浏览次数:21016 次 
                    
                        
                         C#线程中操作出现异常,希望有人能帮忙看下,弄很久了
应用程序: 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();