public ExclusiveBlockConfiguration(ExclusiveLockOptions options = null) { var exOptions = options ?? new ExclusiveLockOptions(); LockTimeout = TimeSpan.FromSeconds(Math.Max(exOptions.LockTimeoutInSeconds, 5)); PollingTime = TimeSpan.FromSeconds(Math.Max(exOptions.PollingTimeInSeconds, 1)); WaitTimeout = TimeSpan.FromSeconds(Math.Max(exOptions.WaitTimeoutInSeconds, 20)); }
/// <summary> /// Executes a named action depending on the chosen algorithm. /// Do not forget to await for the method as this is an asynchronous operation. /// </summary> /// <param name="key">The unique name of the action.</param> /// <param name="operationId">Unique identifier of the caller thread, process or appdomain.</param> /// <param name="blockType">The algorithm of the exclusive execution.</param> /// <param name="options">ExclusiveBlock options</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="action">The code block that will be executed exclusively.</param> /// <returns>A Task that represents the asynchronous operation.</returns> /// <exception cref="DataException">The operation causes a database-related error.</exception> /// <exception cref="TimeoutException">The exclusive lock was not released within the specified time</exception> /// <exception cref="OperationCanceledException">The operation has been cancelled.</exception> public static Task RunAsync(string key, string operationId, ExclusiveBlockType blockType, ExclusiveLockOptions options, CancellationToken cancellationToken, Func <Task> action) { return(RunAsync(key, operationId, blockType, new ExclusiveBlockConfiguration(options), cancellationToken, action)); }