Hi
I'm using this code
ReaderWriterLockSlim myLock = new ReaderWriterLockSlim ();
public void StartLogin()
{
if (myLock.IsWriteLockHeld)
Log.Debug(tag, "Login in progress");
else
{
try
{
myLock.EnterWriteLock();
// launch asynchronous process that will launch loginComplete when complete
}
catch (Exception e)
{
if (myLock.IsWriteLockHeld)
myLock.ExitWriteLock();
}
private void loginComplete()
{
try
{// do some processing
}
finally
{
if (myLock.IsWriteLockHeld)
myLock.ExitWriteLock();
}
}
The first time round, this works as expected. The second time however,
myLock.IsWriteLockHeld will return true in the first line of StartLogin -
that is because in the finallyClause of loginComplete,
myLock.IsWriteLockHeld is false - so the lock is acquired, but never
released. I know that despite using callbacks and performing the actual
login in a background task, myLock is only declared once so I don't
understand why at one point in time it says the lock is acquired, and
another time it doesn't (to make matters worse, I have another method to
logs out and logs in again when I change my settings, and there,
loginLock.IsWriteLockHeld is false in StartLogin, but acquiring the lock
silently bombs the whole process (as before... nothing happens... the code
simply doesn't progress beyond loginLock.EnterWriteLock. If I replace
loginLock.EnterWriteLock with TryEnterWriteLock, then it returns false after
my timeout.
Have I picked another object that's only partially implemented?
Regards
Stephan
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/ReaderWriterLockSlim-fully-implemented-tp5711849.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid