C#中的信号量超时机制

发布于 2024-08-05 07:39:22 字数 154 浏览 4 评论 0原文

有谁知道 .NET 如何处理调用 Semaphore.WaitOne(timeout) 的超时?

我期望出现 TimeoutException,但 MSDN 文档并未将其列在预期异常列表中,而且我似乎无法在任何地方找到它的记录。

Does anyone know how .NET handles a timeout on a call to Semaphore.WaitOne(timeout)?

I'd expect a TimeoutException, but the MSDN documentation doesn't list this in the list of expected exceptions, and I can't seem to find it documented anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2024-08-12 07:39:22

如果超时,该方法将返回 false;如果返回信号,则返回 true

if (mySemaphore.WaitOne(1000))
{
    // signal received
}
else
{
    // wait timed out
}

The method will return false if it times out, and true if it returns a signal:

if (mySemaphore.WaitOne(1000))
{
    // signal received
}
else
{
    // wait timed out
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文