MFCでのスレッド生成とのギャップを埋めるべく・・
そして、AutoResetEvent、ManualResetEventの動作・性質の違いを見いだせないまま・・
※コードが長いため省略しています。
protected static ManualResetEvent m_Idle = new ManualResetEvent(false);
protected static ManualResetEvent m_Command = new ManualResetEvent(false);
protected static ManualResetEvent m_Exit = new ManualResetEvent(false);
public void ThreadRun()
{
WaitHandle[] WaitEvents = new WaitHandle[] {
m_Idle,
m_Command,
m_Exit
};
while (true)
{
int nWE_Index = ManualResetEvent.WaitAny(WaitEvents);
if (nWE_Index == 2)
{
break;
}
switch (nWE_Index)
{
case 0: ///IDLE
ProcIdle(nWE_Index);
break;
case 1: ///command
ProcCommand(nWE_Index);
break;
}
}
//後始末
WaitEvents[0].Close();
WaitEvents[1].Close();
WaitEvents[2].Close();
}
WaitForMultipleObjectsExを使ったハンドシェイク通信をベースとしたのだが・・
なんだかピントこない。。
C#.Netというか、.Netを頭の中で消化できてない気がしてます。
機械相手に通信プログラムを組む事もあるのでWaitForMultipleObjectsExは重宝しています。
MFCのままでも良いのでは?という心の中で葛藤してる今日このごろ(汗