Creating a Mutex throws a DirectoryNotFoundException
I'm trying to create a named mutex, but when I call the constructor I get a DirectoryNotFoundException
! Why is a mutex trying to access the filesystem, and how do I know what is a valid path? Is there any particular directory the mutex should be placed in, and how does that correspond to the name?
EDIT: I'm using the Mutex(bool, string)
overload, and the exception is:
System.IO.DirectoryNotFo开发者_运维问答undException: 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)
Ah, found what the problem was. My mutex name had \
in it, which windows was interpreting as a path character. Running:
mutexName = mutexName.Replace(Path.DirectorySeparatorChar, '_');
fixes the problem
精彩评论