0

我想在 ManualResetEvent 阻止线程后调用 _myThread.Abort()。所以要么我想检查线程是否已经被阻塞,要么我想调用一个只在线程暂停后调用 _myThread.Abort() 的委托。

到目前为止,我得到了:

public void MyPause()
{
    if (_myManualResetEvent == null)
        return;
    else
        _myManualResetEvent.Reset();
}
public void MyResume()
{
    if (_myManualResetEvent == null)
        return;
    else
        _myManualResetEvent.Set();
}
public void MyAbort()
{
    if (_myManualResetEvent == null)
        return;
    else
    {
    //???
    }
}

像询问 _myManualResetEvent.WaitOne(0) 这样的事情不起作用,因为它只是返回 ManualResetEvent 的状态,这可能与实际线程状态不同,但我想知道线程是否已经被阻塞(这意味着它已经调用等待一个())。检查线程状态不起作用,因为 ManualResetEvent 使用 System.Threading.ThreadState.WaitSleepJoin,就像许多其他函数一样。

4

0 回答 0