2011-12-04 55 views
0

此錯誤從未發生過。這是我的代碼;process_OutputDataReceived沒有超載與委託相匹配System.Diagnostics.DataReceivedEventHandler

 private Process process = null; 
    private void button5_Click(object sender, EventArgs e) 
    { 
     if (null != process) 
     { 
      process.Dispose(); 
     } 

     process = new Process(); 
     process.StartInfo.FileName = "world.exe"; 
     process.StartInfo.Arguments = ""; 
     process.StartInfo.UseShellExecute = false; 
     process.EnableRaisingEvents = true; 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.RedirectStandardOutput = true; 

     process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); 
     process.Exited += new EventHandler(process_Exited); 
     process.Start(); 
     process.BeginOutputReadLine(); 
    } 

    private void process_OutputDataReceived(object sender, DataReceivedEventArgs e) 
    { 
    } 

以下是我對得到一個錯誤:

  process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); 

,上面是罰款,直到我寫了;

private void process_OutputDataReceived(object sender, DataReceivedEventArgs e) 
    { 
    } 

幫助將不勝感激。不知道這可能是如何具體比它是。

回答

1

我能想到的唯一的事情就是你有一個命名空間衝突(即你的環境中有其他類與正在使用的類的名稱相匹配)。

嘗試使用明確的命名空間聲明:

process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived); 

    private void process_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e) 
    { 
    } 
+0

感謝萌芽狀態。它現在有效。 ;) –

+0

優秀!記住,在這個網站上點擊複選框和向上箭頭可以幫助你解決問題,或者幫助你解決問題,這樣未來的訪問者知道哪個答案可以幫助你。 –

相關問題