ポートから信号を取得したいのですが、これらの関数を使用してデータを受信しましたが、thread.join() 行でこの例外が発生することがあります。
System.IO.IOException が処理されませんでした
Message="I/O 操作は、スレッドの終了またはアプリケーションの要求により中止されました。
ブレークポイントを挿入してデバッグすると、オンライン thread.join() になるまで正しくなり、UI が停止して何も起こりません。
また、プログラムをリリース モードで実行すると正しく動作しますが、問題はデバッグ モードにあります。
thnx。
public SignalReader()
{
thread = new Thread(new ThreadStart(ThreadMain));
}
public void Start(string portName, int rate)
{
Stop();
try
{
port = new SerialPort(portName, rate);
port.Open();
}
catch
{
;
}
thread.Start();
}
public void Stop()
{
try
{
if (port != null)
{
if (port.IsOpen) port.Close();
if (thread.IsAlive) thread.Join();
port.Dispose();
port = null;
}
}
catch (Exception ex)
{
MessageBox.Show("4:" + ex.ToString());
}
}
ポートを閉じてスレッドに参加する順序を入れ替えると:
...
thread.Join();
port.Close();
...
同じ話が存在します。