G
Guest
I'm dying here... I have an object that I use to access objects in the
session state. I may be reading and writing at the same time, so I am trying
to make the accessors thread safe using ReaderWriter locks. Here's a
stripped down example of my class:
Class SessionLogic{
private static ReaderWriterLock myObjectLock = new ReaderWriterLock();
....
public MyObject MyObject{
get
{
MyObject foo = null;
myObjectLock.AcquireReaderLock(5000);
try
{
foo = this.session["MyObject"] as MyObject;
try
{
LockCookie monster = myObjectLock.UpgradeToWriterLock(5000);
try
{
foo = new MyObject();
this.session["MyObject"] = foo;
}
finally
{
myObjectLock.DowngradeFromWriterLock(ref monster);
}
}
catch (Exception ex)
{
string message = ex.Message; // just so I can see
}
finally
{
myObjectLock.ReleaseReaderLock();
}
return foo;
}
}
}
This structure is almost word for word out of MS' documentation on
ReaderWriterLock. Yet whenever I run it, I get an error: "Attempt to
release mutex not owned by caller." What the... Its the ONLY CALLER! What
is happening here????
session state. I may be reading and writing at the same time, so I am trying
to make the accessors thread safe using ReaderWriter locks. Here's a
stripped down example of my class:
Class SessionLogic{
private static ReaderWriterLock myObjectLock = new ReaderWriterLock();
....
public MyObject MyObject{
get
{
MyObject foo = null;
myObjectLock.AcquireReaderLock(5000);
try
{
foo = this.session["MyObject"] as MyObject;
try
{
LockCookie monster = myObjectLock.UpgradeToWriterLock(5000);
try
{
foo = new MyObject();
this.session["MyObject"] = foo;
}
finally
{
myObjectLock.DowngradeFromWriterLock(ref monster);
}
}
catch (Exception ex)
{
string message = ex.Message; // just so I can see
}
finally
{
myObjectLock.ReleaseReaderLock();
}
return foo;
}
}
}
This structure is almost word for word out of MS' documentation on
ReaderWriterLock. Yet whenever I run it, I get an error: "Attempt to
release mutex not owned by caller." What the... Its the ONLY CALLER! What
is happening here????