mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-02 03:13:58 +08:00
Synchronization code
This commit is contained in:
@@ -1632,6 +1632,11 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||
{
|
||||
var result = new SugarAsyncLock(this);
|
||||
return result.AsyncLock(timeOutSeconds);
|
||||
}
|
||||
public DynamicBuilder DynamicBuilder()
|
||||
{
|
||||
return new DynamicBuilder(this.Context);
|
||||
|
||||
@@ -114,7 +114,10 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#region API
|
||||
|
||||
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||
{
|
||||
return ScopedContext.AsyncLock(timeOutSeconds);
|
||||
}
|
||||
public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; }
|
||||
public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; }
|
||||
public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; }
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other methods
|
||||
Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30);
|
||||
DynamicBuilder DynamicBuilder();
|
||||
void Tracking<T>(T data) where T : class, new();
|
||||
void Tracking<T>(List<T> data) where T : class, new();
|
||||
|
||||
@@ -436,6 +436,7 @@
|
||||
<Compile Include="Utilities\ExpressionBuilderHelper.cs" />
|
||||
<Compile Include="Utilities\CommonExtensions.cs" />
|
||||
<Compile Include="Utilities\PropertyCallAdapterProvider.cs" />
|
||||
<Compile Include="Utilities\SugarAsyncLock.cs" />
|
||||
<Compile Include="Utilities\SugarRetry.cs" />
|
||||
<Compile Include="Utilities\DataTableExtensions.cs" />
|
||||
<Compile Include="Utilities\ReflectionExtensions.cs" />
|
||||
|
||||
@@ -1189,6 +1189,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
|
||||
{
|
||||
return this.Context.AsyncLock(timeOutSeconds);
|
||||
}
|
||||
public SplitTableContext SplitHelper<T>() where T:class,new()
|
||||
{
|
||||
return this.Context.SplitHelper<T>();
|
||||
|
||||
@@ -851,5 +851,9 @@ namespace SqlSugar
|
||||
{
|
||||
ScopedContext.RemoveConnection(configId);
|
||||
}
|
||||
public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds=30)
|
||||
{
|
||||
return ScopedContext.AsyncLock(timeOutSeconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
Src/Asp.Net/SqlSugar/Utilities/SugarAsyncLock.cs
Normal file
32
Src/Asp.Net/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