一、同步锁
private static readonly object _lock = new object();
///同步锁
public void TestLock()
{
lock (_lock)
{
//需要处理的业务
Console.Write("输出内容");
}
}
二、异步锁
private readonly AsyncLock _mutex = new AsyncLock();
///异步锁
public async Task<bool> TestAsyncLock()
{
using ( await _mutex.LockAsync())
//锁保护区域
{
var result = await _preSaleLawyerService.GetCustomerInfoAsync(new GetCustomerInfoRequest() { CustomerId = request.CustomerId });
}
}