473,326 Members | 2,076 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,326 software developers and data experts.

Easy mutex problem...

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?

In Global.asax:

void Application_Start(object sender, EventArgs e)
{
Application["AppMutex"] = new System.Threading.Mutex();
}

In my page:-

protected void Page_Load(object sender, EventArgs e)
{
if (!((System.Threading.Mutex)Application["AppMutex"]).WaitOne())
Label1.Text = "Cannot lock mutex";
else
Label1.Text = "Mutex locked ok";
}

May 24 '06 #1
4 1618
What are you doing with the mutex? Why do you need one that is global but is
being accessed on a per page basis?

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

<go****@maclark.co.uk> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
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?

In Global.asax:

void Application_Start(object sender, EventArgs e)
{
Application["AppMutex"] = new System.Threading.Mutex();
}

In my page:-

protected void Page_Load(object sender, EventArgs e)
{
if (!((System.Threading.Mutex)Application["AppMutex"]).WaitOne())
Label1.Text = "Cannot lock mutex";
else
Label1.Text = "Mutex locked ok";
}

May 24 '06 #2
I was trying to control access to a resource at an application level,
not per-page-level or session-level.

May 24 '06 #3
I figured that was what you were after. I mutex is really overkill for that
situation. Just lock the resource. As to the original issue, I'm not sure
why it is happening. Maybe if you could scratch up some code to reproduce
the issue, we could look at it.

lock(resource)
{
}

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

"Vodzurk" <go****@maclark.co.uk> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
I was trying to control access to a resource at an application level,
not per-page-level or session-level.

May 24 '06 #4
You also need to explicitly release the mutex object by the way which is why
the mutex isn't being released. Since it is a kernel object, it isn't scoped
to the block of code it is running in.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

<go****@maclark.co.uk> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
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?

In Global.asax:

void Application_Start(object sender, EventArgs e)
{
Application["AppMutex"] = new System.Threading.Mutex();
}

In my page:-

protected void Page_Load(object sender, EventArgs e)
{
if (!((System.Threading.Mutex)Application["AppMutex"]).WaitOne())
Label1.Text = "Cannot lock mutex";
else
Label1.Text = "Mutex locked ok";
}

May 25 '06 #5

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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.