0
我正在製作一個應用程序,它正在讀取串口並在WindowsForms應用程序屏幕中更新數據。串口鎖存器應用程序C#
有時,當你試圖關閉該程序被鎖定。 我在使用委託。
我該做什麼錯?
void sp1_LineReceived(object sender, LineReceivedEventArgs Args)
{
Invoke(new Action(() =>
{
// execute code
}));
}
初始化
public FormPrincipal()
{
InitializeComponent();
spSistema.LineReceived += new LineReceivedEventHandler(sp1_LineReceived);
// next codes
}
Outher碼
public partial class FormPrincipal : Form
{
SerialPort spSimulador = new SerialPort();
public static PortaSerial spSistema = new PortaSerial();
你正確關閉退出串口? –
當設備發送時使用Close()方法時,很可能導致死鎖。使用BeginInvoke()或刪除Close()或在工作線程上運行Close。 –