【问题标题】:Creating a Mutex throws a DirectoryNotFoundException创建互斥体会引发 DirectoryNotFoundException
【发布时间】:2010-11-30 12:30:45
【问题描述】:

我正在尝试创建一个named mutex,但是当我调用构造函数时,我得到一个DirectoryNotFoundException!为什么互斥锁试图访问文件系统,我怎么知道什么是有效路径?互斥体是否应该放置在任何特定目录中,与名称有何对应关系?

编辑:我正在使用Mutex(bool, string) 重载,例外是:

System.IO.DirectoryNotFoundException: Could not find a part of the path '<mutex name>'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Threading.Mutex.<>c__DisplayClass3.<.ctor>b__0(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew, MutexSecurity mutexSecurity)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)

【问题讨论】:

  • 你使用的是什么构造函数,异常的细节是什么?
  • 哎呀。这个问题是在 15 分钟前发布的,它已经是 Google 搜索“mutex directorynotfoundexception”的第二个结果。爬得真快。
  • 哇!此 DirectoryNotFoundException 完全具有误导性。

标签: .net mutex


【解决方案1】:

啊,找到问题所在了。我的互斥锁名称中包含\,Windows 将其解释为路径字符。运行:

mutexName = mutexName.Replace(Path.DirectorySeparatorChar, '_');

解决问题

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 2012-12-09
相关资源
最近更新 更多