mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-21 18:48:27 +08:00
Add db.AsyncLock
This commit is contained in:
@@ -1632,6 +1632,11 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Other
|
#region Other
|
||||||
|
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||||
|
{
|
||||||
|
var result = new SugarAsyncLock(this);
|
||||||
|
return result.AsyncLock(timeOutSeconds);
|
||||||
|
}
|
||||||
public DynamicBuilder DynamicBuilder()
|
public DynamicBuilder DynamicBuilder()
|
||||||
{
|
{
|
||||||
return new DynamicBuilder(this.Context);
|
return new DynamicBuilder(this.Context);
|
||||||
|
|||||||
@@ -114,7 +114,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region API
|
#region API
|
||||||
|
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||||
|
{
|
||||||
|
return ScopedContext.AsyncLock(timeOutSeconds);
|
||||||
|
}
|
||||||
public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; }
|
public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; }
|
||||||
public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; }
|
public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; }
|
||||||
public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; }
|
public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; }
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Other methods
|
#region Other methods
|
||||||
|
Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30);
|
||||||
DynamicBuilder DynamicBuilder();
|
DynamicBuilder DynamicBuilder();
|
||||||
void Tracking<T>(T data) where T : class, new();
|
void Tracking<T>(T data) where T : class, new();
|
||||||
void Tracking<T>(List<T> data) where T : class, new();
|
void Tracking<T>(List<T> data) where T : class, new();
|
||||||
|
|||||||
@@ -1189,6 +1189,10 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
|
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||||
|
{
|
||||||
|
return this.Context.AsyncLock(timeOutSeconds);
|
||||||
|
}
|
||||||
public SplitTableContext SplitHelper<T>() where T:class,new()
|
public SplitTableContext SplitHelper<T>() where T:class,new()
|
||||||
{
|
{
|
||||||
return this.Context.SplitHelper<T>();
|
return this.Context.SplitHelper<T>();
|
||||||
|
|||||||
@@ -851,5 +851,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
ScopedContext.RemoveConnection(configId);
|
ScopedContext.RemoveConnection(configId);
|
||||||
}
|
}
|
||||||
|
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds=30)
|
||||||
|
{
|
||||||
|
return ScopedContext.AsyncLock(timeOutSeconds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
Src/Asp.NetCore2/SqlSugar/Utilities/SugarAsyncLock.cs
Normal file
32
Src/Asp.NetCore2/SqlSugar/Utilities/SugarAsyncLock.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SugarAsyncLock : IDisposable
|
||||||
|
{
|
||||||
|
static readonly SemaphoreSlim SemaphoreSlim =new SemaphoreSlim(1);
|
||||||
|
|
||||||
|
|
||||||
|
public SugarAsyncLock(SqlSugarProvider db)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<SugarAsyncLock> AsyncLock(int timeOutSeconds)
|
||||||
|
{
|
||||||
|
TimeSpan timeout = TimeSpan.FromSeconds(timeOutSeconds);
|
||||||
|
await SemaphoreSlim.WaitAsync(timeout);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
SemaphoreSlim.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user