Synchronization helper: a static lock collection associated with a key. NamedLock manages the lifetime of critical sections that can be accessed by a key (name) throughout the application. It also have some helper methods to allow a maximum wait time (timeout) to aquire the lock and safelly release it. Note: this nuget package contains c# source code and depends on System.Collections.Concurrent introduced in .Net 4.0.
Inheritance: IDisposable
示例#1
0
 /// <summary>
 /// Creates a new instance and tries to aquire a lock.
 /// </summary>
 /// <param name="key">The named lock key.</param>
 /// <param name="waitTimeoutMilliseconds">The wait timeout milliseconds.</param>
 public static NamedLock CreateAndEnter (string key, int waitTimeoutMilliseconds)
 {
     NamedLock item;
     item = new NamedLock (key);
     item.Enter (waitTimeoutMilliseconds);
     return item;
 }
示例#2
0
 /// <summary>
 /// Creates a new instance and tries to aquire a lock.
 /// </summary>
 /// <param name="key">The named lock key.</param>
 public static NamedLock CreateAndEnter (string key)
 {
     NamedLock item;
     item = new NamedLock (key);
     item.Enter ();
     return item;
 }