時間が0のTryEnterを静的に呼び出すと、ロックが利用可能になった場合にロックが取得されないことが保証されているかどうかはわかりません。同期変数がロックされていた私は、デバッグモードでテストするためにやったソリューションは、以下を使用していました:
#if DEBUG
// Make sure we're inside a lock of the SyncRoot by trying to lock it.
// If we're able to lock it, that means that it wasn't locked in the first
// place. Afterwards, we release the lock if we had obtained it.
bool acquired = false;
try
{
acquired = Monitor.TryEnter(SyncRoot);
}
finally
{
if (acquired)
{
Monitor.Exit(SyncRoot);
}
}
Debug.Assert(acquired == false, "The SyncRoot is not locked.");
#endif
はい、 ありがとうございました。それは、私がすでに思ったことをかなり確認します。 –