public void Replace(Func <T, T> replacer) { using (var manager = new LockManager(resourceLock)) { manager.EnterWriteLock(); var resource = GetResource(); var newResource = replacer(resource); SaveResource(newResource, filename); } }
void IDisposable.Dispose() { try { save(Resource); } finally { manager.Dispose(); manager = null; Resource = null; } }
public ResourceReader(Func <T> resource, ReaderWriterLockSlim resourceLock) { try { manager = new LockManager(resourceLock); manager.EnterUpgradeableReadLock(); Resource = resource(); manager.DowngradeToRead(); } catch { manager.Dispose(); throw; } }
public ResourceWriter(Func <T> resource, ReaderWriterLockSlim resourceLock, Action <T> save) { try { manager = new LockManager(resourceLock); manager.EnterWriteLock(); Resource = resource(); this.save = save; } catch { manager.Dispose(); throw; } }