Cha*_*van 5 .net semaphore ioexception
以下代码在Windows 2008上失败了.它在Win7中成功.
return new Semaphore(1, 1, "my-test-semaphore");
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
我四处搜寻,找不到解释.有没有人有任何想法?
您是错误报告中的错误的受害者.异常消息很奇怪,因为它使用的WinIOError()方法与SerialPort类共享.当Windows错误代码为2(找不到文件)或3(找不到路径)时,您将收到仅适用于串行端口的异常消息.因此怪异的"指定的端口不存在"消息.
我是你的代码片段的受害者,你混淆了真正的问题.您使用的信号量名称实际上不是"my-test-semaphore".我无法猜测它的真实外观,但它违反了正确命名的Windows对象的规则.它可能看起来像"backslashes\\are not okay".
修复信号量名称.
| 归档时间: |
|
| 查看次数: |
306 次 |
| 最近记录: |