代码之家  ›  专栏  ›  技术社区  ›  thecoop

创建互斥体会引发DirectoryNotFoundException

  •  16
  • thecoop  · 技术社区  · 15 年前

    我正在尝试创建一个 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)
    
    1 回复  |  直到 15 年前
        1
  •  19
  •   thecoop    15 年前

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

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

    解决了问题