HttpApplicationState and lock() question

N

nano2k

Hi
Inside webservices we can access the Application object which is an
HttpApplicationState instance.
Using Application object, I defined a state variable named
"fileManager":

FileManager fm = new FileManager();
Application["fileManager"] = fm;

When executing some actions, I need exclusive access to this object.
My current code is like this:

FileManager fm = Application["fileManager"] as FileManager;
lock(fm) {
//... use fm
}

My questions:
1. Does this design effectively protects my fm object? I mean will
lock statement work?
2. Does the isolation level of the application affect this expected
behavior? I'm particularily refering to isolation level Medium
(Pooled) and High (Isolated). Do these levels require named mutexes?

Another (IMO: bad) solution would be:

Application.Lock();
try {
FileManager fm = Application["fileManager"] as FileManager;
//... use fm
}
finally {
Application.UnLock();
}

but this solution block ALL other requests until this piece of code is
executed, which is not good.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top