【问题标题】:.NET Creating a Semaphore fails with IoException on Win 2008.NET 在 Win 2008 上创建信号量失败并出现 IoException
【发布时间】:2013-12-31 06:22:38
【问题描述】:

以下代码在 Windows 2008 上对我来说是失败的。它在 Win7 中成功。

return new Semaphore(1, 1, "my-test-semaphore");

我收到以下错误:

System.IO.IOException: The specified port does not exist.
  at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
  at System.IO.Ports.InternalResources.WinIOError()
  at System.Threading.Semaphore..ctor(Int32 initialCount, Int32 maximumCount, String name)
  at Throttle.Program.CreateSemaphore(String passthroughApplication)
  at Throttle.Program.Main(String[] args)

我四处寻找,找不到解释。有人有什么想法吗?

【问题讨论】:

    标签: .net semaphore ioexception


    【解决方案1】:

    您是错误报告中的错误的受害者。异常消息很奇怪,因为它使用的 WinIOError() 方法与 SerialPort 类共享。当 Windows 错误代码为 2(未找到文件)或 3(未找到路径)时,您会收到仅适用于串行端口的异常消息。因此奇怪的“指定端口不存在”消息。

    我是你的代码 sn-p 的受害者,你混淆了真正的问题。您使用的信号量名称实际上不是“my-test-semaphore”。我猜不出它真正的样子,但它违反了正确命名的 Windows 对象的规则。它可能看起来像 "backslashes\\are not okay"

    修正信号量名称。

    【讨论】:

    • 哇。这就是我要说的。哇。我在任何地方都找不到记录的信号量命名限制。尽管如此,非常感谢您看透我的错误失败案例并发布解决方案。我现在正在对信号量名称的一部分进行哈希处理,所以问题解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2012-07-10
    相关资源
    最近更新 更多