Note: I'm not a ReaderWriterLockSlim expert, I just play one on TV (and ask around on IRC...)
I'm told that "you can't do [what you're doing]"; specifically, ReaderWriterLockSlim locks are per-thread. You can't acquire the lock on one thread and release it on another. Thus, IsWriteLockHeld should not be used for this purpose. (Assuming that we're reading the code properly...). If we're misinterpreting your code, could you please provide a test project for diagnostic purposes? Thanks, - Jon On Sep 18, 2012, at 8:49 AM, Stephan Steiner <[email protected]> wrote: > 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 _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
