473,671 Members | 2,250 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 1063
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

193
9531
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
4772
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
3149
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
3
5550
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
8
574
by: Dan Pavel | last post by:
Hi, I did not used Mutex before and I need now. I have an application that control some workflows on different machines. I use SNMP for that. The problem is that the thread used for starting an workflow need to write in some OID. When I start 2 workflows on the same machine the second thread need to wait for the first one to finish and after that continue work. This works OK. The problem is when I have to start 2 workflows on different...
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7437
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
4225
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
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
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
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
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.