Skip to content

Instantly share code, notes, and snippets.

@jeremydmiller
Created November 9, 2011 18:25
Show Gist options
  • Save jeremydmiller/1352358 to your computer and use it in GitHub Desktop.
Save jeremydmiller/1352358 to your computer and use it in GitHub Desktop.
public static class ReaderWriterLockExtensions
{
public static void Write(this ReaderWriterLockSlim rwLock, Action action)
{
rwLock.EnterWriteLock();
try
{
action();
}
finally
{
rwLock.ExitWriteLock();
}
}
public static void Read(this ReaderWriterLockSlim rwLock, Action action)
{
rwLock.EnterReadLock();
try
{
action();
}
finally
{
rwLock.ExitReadLock();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment