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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top