.NET在Win 2008上创建信号量失败,出现IoException
以下代码在Windows 2008上失败。它在Win7中成功.NET在Win 2008上创建信号量失败,出现IoException,.net,semaphore,ioexception,.net,Semaphore,Ioexception,以下代码在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.In
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)
我到处找了找,找不到解释。有人有什么想法吗?您是错误报告中错误的受害者。异常消息很奇怪,因为它使用的WinIOError()方法与SerialPort类共享。当Windows错误代码为2(未找到文件)或3(未找到路径)时,您会收到仅适用于串行端口的异常消息。因此,古怪的“指定端口不存在”消息 我是你代码片段的受害者,你混淆了真正的问题。您使用的信号量名称实际上不是“我的测试信号量”。我猜不出它到底是什么样子,但它违反了正确命名的Windows对象的规则。它可能看起来像
“反斜杠\\不正常”
修复信号灯名称。Bug提交:哇。这就是我要说的。哇!我找不到任何地方记录的信号量命名限制。尽管如此,非常感谢您看穿了我的故障案例并发布了解决方案。我现在正在对信号量名称的一部分进行哈希运算,所以问题就解决了。