| | |
| | | } |
| | | } |
| | | |
| | | private readonly SemaphoreSlim _asyncLock = new SemaphoreSlim(1, 1); |
| | | |
| | | public async Task<WebResponseContent> BeginTranAsync(Func<Task<WebResponseContent>> funcAsync) |
| | | { |
| | | await _asyncLock.WaitAsync(); |
| | | try |
| | | { |
| | | BeginTran(); // 假设这是同步方法,启动事务 |
| | | WebResponseContent content = await funcAsync(); |
| | | if (content.Status) |
| | | CommitTran(); // 同步提交 |
| | | else |
| | | RollbackTran(); // 同步回滚 |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | _asyncLock.Release(); |
| | | } |
| | | } |
| | | |
| | | public void CommitTran() |
| | | { |
| | | lock (this) |