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_Sta rt(object sender, EventArgs e)
{
Application["AppMutex"] = new System.Threadin g.Mutex();
}
In my page:-
protected void Page_Load(objec t sender, EventArgs e)
{
if (!((System.Thre ading.Mutex)App lication["AppMutex"]).WaitOne())
Label1.Text = "Cannot lock mutex";
else
Label1.Text = "Mutex locked ok";
} 4 1641
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******** *************@i 39g2000cwa.goog legroups.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_Sta rt(object sender, EventArgs e) { Application["AppMutex"] = new System.Threadin g.Mutex(); }
In my page:-
protected void Page_Load(objec t sender, EventArgs e) { if (!((System.Thre ading.Mutex)App lication["AppMutex"]).WaitOne()) Label1.Text = "Cannot lock mutex"; else Label1.Text = "Mutex locked ok"; }
I was trying to control access to a resource at an application level,
not per-page-level or session-level.
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.goo glegroups.com.. . I was trying to control access to a resource at an application level, not per-page-level or session-level.
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******** *************@i 39g2000cwa.goog legroups.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_Sta rt(object sender, EventArgs e) { Application["AppMutex"] = new System.Threadin g.Mutex(); }
In my page:-
protected void Page_Load(objec t sender, EventArgs e) { if (!((System.Thre ading.Mutex)App lication["AppMutex"]).WaitOne()) Label1.Text = "Cannot lock mutex"; else Label1.Text = "Mutex locked ok"; } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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
|
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
|
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
| |
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
|
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
|
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.
|
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:
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |