Mutex problem...

L

Lloyd Dupont

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)
 
L

Lloyd Dupont

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top