I have some code where I updatde a file (that might not exist yet).
In fact this file contains 2 integers and is used in only one function. I
thought overkill to configure, deploy and maintain a database to store 2
numbers, so I'm just trying to use a Mutex to be sure only one of my process
at a time would access the file.

my code looks like that:
public static uint GetUID(string filename, byte keyType, byte reseller)
{
using (Mutex mutex = new Mutex(false, "uidfile:" + filename))
{
mutex.WaitOne();

// blablablabla
}
}

And this worked well in a little desktop application I was using to test it.

Next I tryed to use this code on a WebServer (in a generic handler / .ashx)

And I get the error below on the mutex constructor.
How could it be?
what could I do?
(remember the file might not exist yet anyway!)
=== the error ====
System.IO.DirectoryNotFoundException was unhandled by user code
Message="Could not find a part of the path
'uidfile:F:\\MyWork\\eCookBook\\WebSite\\asp.net\\App_Data\\maxuids.file'."
Source="mscorlib"
StackTrace:
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)
at PowerGui.Utils.SimpleLicenceKey.GetUID(String filename, Byte
keyType, Byte reseller)
at eSellerate.ProcessRequest(HttpContext context) in
f:\MyWork\eCookBook\WebSite\asp.net\eSellerate.ashx:line 37
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

--
I have taken a vow of poverty. If you want to really piss me off, send me
money.

Re: Mutex problem... by Lloyd

Lloyd
Sat Feb 04 00:36:07 CST 2006

I found a work around, I replace all the '/', '\' and ':' by '_' and it
worked.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:%23JwgrlUKGHA.524@TK2MSFTNGP09.phx.gbl...
>I have some code where I updatde a file (that might not exist yet).
> In fact this file contains 2 integers and is used in only one function. I
> thought overkill to configure, deploy and maintain a database to store 2
> numbers, so I'm just trying to use a Mutex to be sure only one of my
> process at a time would access the file.
>
> my code looks like that:
> public static uint GetUID(string filename, byte keyType, byte reseller)
> {
> using (Mutex mutex = new Mutex(false, "uidfile:" + filename))
> {
> mutex.WaitOne();
>
> // blablablabla
> }
> }
>
> And this worked well in a little desktop application I was using to test
> it.
>
> Next I tryed to use this code on a WebServer (in a generic handler /
> .ashx)
>
> And I get the error below on the mutex constructor.
> How could it be?
> what could I do?
> (remember the file might not exist yet anyway!)
> === the error ====
> System.IO.DirectoryNotFoundException was unhandled by user code
> Message="Could not find a part of the path
> 'uidfile:F:\\MyWork\\eCookBook\\WebSite\\asp.net\\App_Data\\maxuids.file'."
> Source="mscorlib"
> StackTrace:
> 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)
> at PowerGui.Utils.SimpleLicenceKey.GetUID(String filename, Byte
> keyType, Byte reseller)
> at eSellerate.ProcessRequest(HttpContext context) in
> f:\MyWork\eCookBook\WebSite\asp.net\eSellerate.ashx:line 37
> at
> System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
> at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
> Boolean& completedSynchronously)
>
> --
> I have taken a vow of poverty. If you want to really piss me off, send me
> money.
>
>