Exemple #1
0
 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);
     }
 }
Exemple #2
0
 void IDisposable.Dispose()
 {
     try
     {
         save(Resource);
     }
     finally
     {
         manager.Dispose();
         manager  = null;
         Resource = null;
     }
 }
Exemple #3
0
 public ResourceReader(Func <T> resource, ReaderWriterLockSlim resourceLock)
 {
     try
     {
         manager = new LockManager(resourceLock);
         manager.EnterUpgradeableReadLock();
         Resource = resource();
         manager.DowngradeToRead();
     }
     catch
     {
         manager.Dispose();
         throw;
     }
 }
Exemple #4
0
 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;
     }
 }