473,785 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Direc toryNotFoundExc eption was unhandled by user code
Message="Could not find a part of the path
'uidfile:F:\\My Work\\eCookBook \\WebSite\\asp. net\\App_Data\\ maxuids.file'."
Source="mscorli b"
StackTrace:
at System.IO.__Err or.WinIOError(I nt32 errorCode, String
maybeFullPath)
at System.Threadin g.Mutex.<>c__Di splayClass3.<.c tor>b__0(Object
userData)
at
System.Runtime. CompilerService s.RuntimeHelper s.ExecuteCodeWi thGuaranteedCle anup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threadin g.Mutex..ctor(B oolean initiallyOwned, String name,
Boolean& createdNew, MutexSecurity mutexSecurity)
at System.Threadin g.Mutex..ctor(B oolean initiallyOwned, String name)
at PowerGui.Utils. SimpleLicenceKe y.GetUID(String filename, Byte
keyType, Byte reseller)
at eSellerate.Proc essRequest(Http Context context) in
f:\MyWork\eCook Book\WebSite\as p.net\eSellerat e.ashx:line 37
at
System.Web.Http Application.Cal lHandlerExecuti onStep.System.W eb.HttpApplicat ion.IExecutionS tep.Execute()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step,
Boolean& completedSynchr onously)

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

"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** *******@TK2MSFT NGP09.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.Direc toryNotFoundExc eption was unhandled by user code
Message="Could not find a part of the path
'uidfile:F:\\My Work\\eCookBook \\WebSite\\asp. net\\App_Data\\ maxuids.file'."
Source="mscorli b"
StackTrace:
at System.IO.__Err or.WinIOError(I nt32 errorCode, String
maybeFullPath)
at System.Threadin g.Mutex.<>c__Di splayClass3.<.c tor>b__0(Object
userData)
at
System.Runtime. CompilerService s.RuntimeHelper s.ExecuteCodeWi thGuaranteedCle anup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threadin g.Mutex..ctor(B oolean initiallyOwned, String name,
Boolean& createdNew, MutexSecurity mutexSecurity)
at System.Threadin g.Mutex..ctor(B oolean initiallyOwned, String name)
at PowerGui.Utils. SimpleLicenceKe y.GetUID(String filename, Byte
keyType, Byte reseller)
at eSellerate.Proc essRequest(Http Context context) in
f:\MyWork\eCook Book\WebSite\as p.net\eSellerat e.ashx:line 37
at
System.Web.Http Application.Cal lHandlerExecuti onStep.System.W eb.HttpApplicat ion.IExecutionS tep.Execute()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step,
Boolean& completedSynchr onously)

--
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
3804
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 application runs under the standard asp.net user account. The problem relates to permissions on creation of the mutex. If the asp.net application creates the mutex, the executable cannot access it (access denied error). Likewise, if the...
193
9649
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 speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
2
4782
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 Mutex mtxBezoeken = new Mutex(false, "bezoeken"); which compiles and executes just fine. Then in another page I want to write to a file that may also be accessed by global.asax.cs so I want access to
16
3163
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 ownership, second did not and terminated. In a release build, the second instance *also* got ownership. I "fixed" it by making the mutex a static member of my MainForm class. Did the garbage collector eat my mutex because it is not referenced
4
1641
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 not get a mutex lock. Any ideas? I'm trying to get a globally accessible mutex. Is using the Application object wrong somehow?
1
2064
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 on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
3
4960
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 on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
3
5595
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 the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
11
3694
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 that the Mutex is already owned... but this has the unwanted side effect of seizing ownership of the Mutex in the case where the Mutex is NOT already owned. I'm looking for something like an "IsOwned" property.
2
4872
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: In my AppSettings class: public static Mutex mutexPrinterFile; In my program:
0
10357
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.