[英]Does Not Contain A Constructor That Takes 1 Arguments
我對C#有點陌生,最近在串行通信操作期間丟失串行連接時遇到了“接收無效操作異常”的問題。 我試圖通過private void port_ErrorReceived
捕獲錯誤(請參見下文),但我不斷收到錯誤,指出“不包含采用1個參數的構造函數”。
private void port_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
bool error = false;
// Check if the comport is closed
if (!comport.IsOpen)
{
try
{
// Try to open the port
comport.Open();
}
catch (UnauthorizedAccessException) { error = true; }
catch (IOException) { error = true; }
catch (ArgumentException) { error = true; }
catch (InvalidOperationException) { error = true; }
if (error) MessageBox.Show(this, "No serial port identified. Please check your connection.", "Serial Connection Lost", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
這是我稱之為新事件處理程序的地方:
comport.ErrorReceived += new SerialErrorReceivedEventArgs(port_ErrorReceived);
我在StackOverflow上看到過一些類似的帖子,但是我不太確定什么適用於這種情況。 任何幫助,將不勝感激。 謝謝。
我想你的意思很簡單:
comport.ErrorReceived += port_ErrorReceived;
或更詳細地說:
comport.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived);
(但它們是相同的;沒有理由不使用第一個版本)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.