Example #1
0
 /// <summary>
 /// 使用锁执行一个方法
 /// </summary>
 /// <typeparam name="T">返回对象类型</typeparam>
 /// <param name="lock">业务锁</param>
 /// <param name="key">锁定标识</param>
 /// <param name="expiration">锁定时间间隔</param>
 /// <param name="executeAction">执行的方法</param>
 /// <param name="defaultValue">默认值</param>
 public static async Task <T> ExecuteWithLockAsync <T>(this ILock @lock, string key, TimeSpan expiration, Func <Task <T> > executeAction, T defaultValue = default) =>
 await @lock.ExecuteWithLockAsync(key, "1", expiration, executeAction, defaultValue);
Example #2
0
 /// <summary>
 /// 使用锁执行一个方法
 /// </summary>
 /// <param name="lock">业务锁</param>
 /// <param name="key">锁定标识</param>
 /// <param name="expiration">锁定时间间隔</param>
 /// <param name="executeAction">执行的方法</param>
 public static async Task ExecuteWithLockAsync(this ILock @lock, string key, TimeSpan expiration, Func <Task> executeAction) =>
 await @lock.ExecuteWithLockAsync(key, "1", expiration, executeAction);