2 番目の ManualResetEvent を使用して、メイン スレッドにシグナルを送ることができます。
ワーカースレッドで:
signalEWH.Set();
commonEWH.WaitOne();
signalEWM.Reset();
メインスレッドで
var isWaiting = signalEWH.WaitOne(0);
次のテストアプリを作成しましたが、問題なく動作します
class Program
{
static void Main(string[] args)
{
var thr = new Thread(new ThreadStart(SecondThread));
thr.IsBackground = true;
thr.Start();
firstEvent.WaitOne();
var isSleep = thr.ThreadState.HasFlag(ThreadState.WaitSleepJoin);
}
static ManualResetEvent firstEvent = new ManualResetEvent(false);
static ManualResetEvent secondEvent = new ManualResetEvent(false);
static void SecondThread()
{
firstEvent.Set();
secondEvent.WaitOne();
firstEvent.Reset();
}
}