2016-07-18 36 views
-1

プログラムをデバッグしてプログラムを終了しようとするとエラーが発生し、プログラムが終了し、このエラーが発生します。An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dllC#エラー:System.Windows.Forms.dllで 'System.InvalidOperationException'型の未処理の例外が発生しました。

私には何か間違ったコードがあります。

マイコード:何かが間違っているよう

void proc_OutputDataReceived(object sender, DataReceivedEventArgs e) 
    { 
     if (stop) 
     { 
      var proc = (Process)sender; 

      stop = false; // allows you to spawn a new thread after stopping the first 
      proc.SynchronizingObject = this; // puts the form in charge of async communication 
      proc.Kill(); // terminates the thread 
      proc.WaitForExit(); // thread is killed asynchronously, so this goes here... 

     } 
     if (e.Data != null) 
     { 
      string newLine = e.Data.Trim() + Environment.NewLine; 
      MethodInvoker append =() => { 
       pingInformatsioon.Text += newLine; 
       if (checkBox1.Checked) 
       { 
        WriteLog(newLine); 
       } 
      }; 
      pingInformatsioon.BeginInvoke(append); 
     } 
    } 

は常にpingInformatsioon.BeginInvoke(append);の上に黄色を来..

答えて

1

おそらく、UIスレッド以外のスレッドからこのコードを呼び出しています。この

if (InvokeRequired) 
    pingInformatsioon.BeginInvoke(append); 
else 
    Invoke(append); 
+0

エラー\t CS1501 \t '起動' は0の引数を取る方法はありませんオーバーロードのようなもので

pingInformatsioon.BeginInvoke(append); 

を交換してみてください – KristenL

関連する問題