473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Mutex problem...

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.Exe cuteCodeWithGuaranteedCleanup(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.ash x:line 37
at
System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean& completedSynchronously)

--
I have taken a vow of poverty. If you want to really piss me off, send me
money.
Feb 4 '06 #1
1 1630
I found a work around, I replace all the '/', '\' and ':' by '_' and it
worked.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:%2***************@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.Exe cuteCodeWithGuaranteedCleanup(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.ash x:line 37
at
System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean& completedSynchronously)

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

Feb 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
2
by: Martin Maat | last post by:
Hi. I want to use the same mutex in different classes (web pages in an ASP.NET application). In global.asax.cs, the class that starts up first, I create a Mutex like this: static private...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
4
by: google | last post by:
Hi Guys, I'm having a bizarre problem here with mutexes. If I have the following code in a page (note that it never releases the mutex!), then load the page twice, in 2 seperate browsers, I do...
1
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work...
3
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
11
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce...
2
by: tshad | last post by:
I am running a program as a Windows service which works fine. I am using a Mutex to prevent multiple threads from from accessing my log text file at the same time. It works fine in the Service:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.