Class Lock
An interprocess mutex lock.
Typical use might look like:
    var result = Lock.With.NewAnonymous<string>(
        @lock: directory.MakeLock("my.lock"), 
        lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, 
        doBody: () =>
    {
        //... code to execute while locked ...
        return "the result";
    }).Run();
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Store
Assembly: Lucene.Net.dll
Syntax
public abstract class Lock : IDisposable
  Fields
| Improve this Doc View SourceLOCK_OBTAIN_WAIT_FOREVER
Pass this value to Obtain(Int64) to try forever to obtain the lock.
Declaration
public const long LOCK_OBTAIN_WAIT_FOREVER = -1L
  Field Value
| Type | Description | 
|---|---|
| System.Int64 | 
LOCK_POLL_INTERVAL
How long Obtain(Int64) waits, in milliseconds, in between attempts to acquire the lock.
Declaration
public static long LOCK_POLL_INTERVAL
  Field Value
| Type | Description | 
|---|---|
| System.Int64 | 
Properties
| Improve this Doc View SourceFailureReason
If a lock obtain called, this failureReason may be set with the "root cause" System.Exception as to why the lock was not obtained.
Declaration
protected Exception FailureReason { get; set; }
  Property Value
| Type | Description | 
|---|---|
| System.Exception | 
Methods
| Improve this Doc View SourceDispose()
Releases exclusive access.
Declaration
public void Dispose()
  Dispose(Boolean)
Releases exclusive access.
Declaration
protected abstract void Dispose(bool disposing)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Boolean | disposing | 
IsLocked()
Returns true if the resource is currently locked.  Note that one must
still call Obtain() before using the resource.
Declaration
public abstract bool IsLocked()
  Returns
| Type | Description | 
|---|---|
| System.Boolean | 
NewAnonymous<T>(Lock, Int32, Func<T>)
Creates a new instance with the ability to specify the DoBody() method
through the doBody argument
Simple example:
    var result = Lock.With.NewAnonymous<string>(
        @lock: directory.MakeLock("my.lock"), 
        lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, 
        doBody: () =>
    {
        //... code to execute while locked ...
        return "the result";
    }).Run();
The result of the operation is the value that is returned from doBody
(i.e. () => { return "the result"; }). The type of 
Declaration
public static Lock.With<T> NewAnonymous<T>(Lock lock, int lockWaitTimeout, Func<T> doBody)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Lock | lock | the Lock instance to use  | 
      
| System.Int32 | lockWaitTimeout | length of time to wait in milliseconds or LOCK_OBTAIN_WAIT_FOREVER to retry forever  | 
      
| System.Func<T> | doBody | a delegate method that  | 
      
Returns
| Type | Description | 
|---|---|
| Lock.With<T> | The value that is returned from the   | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | 
Obtain()
Attempts to obtain exclusive access and immediately return upon success or failure. Use Dispose() to release the lock.
Declaration
public abstract bool Obtain()
  Returns
| Type | Description | 
|---|---|
| System.Boolean | true iff exclusive access is obtained  | 
      
Obtain(Int64)
Attempts to obtain an exclusive lock within amount of
time given. Polls once per LOCK_POLL_INTERVAL
(currently 1000) milliseconds until lockWaitTimeout is
passed.
Declaration
public bool Obtain(long lockWaitTimeout)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Int64 | lockWaitTimeout | length of time to wait in milliseconds or LOCK_OBTAIN_WAIT_FOREVER to retry forever  | 
      
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
  | 
      
Exceptions
| Type | Condition | 
|---|---|
| LockObtainFailedException | if lock wait times out  | 
      
| System.ArgumentException | if   | 
      
| System.IO.IOException | if Obtain() throws System.IO.IOException  |