mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Asynchronous thread optimization
This commit is contained in:
parent
845dbd99e9
commit
634867d495
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@ -748,8 +749,17 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
IsSingleInstance = true;
|
||||
result = NoSameThread();
|
||||
StackTrace st = new StackTrace(true);
|
||||
var methods = st.GetFrames();
|
||||
var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
|
||||
if (isAsync)
|
||||
{
|
||||
result = Synchronization();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NoSameThread();
|
||||
}
|
||||
}
|
||||
if (result.Root == null)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -44,6 +45,29 @@ namespace SqlSugar
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static bool IsAnyAsyncMethod(StackFrame[] methods)
|
||||
{
|
||||
bool isAsync = false;
|
||||
foreach (var item in methods)
|
||||
{
|
||||
if (UtilMethods.IsAsyncMethod(item.GetMethod()))
|
||||
{
|
||||
isAsync = true;
|
||||
}
|
||||
}
|
||||
return isAsync;
|
||||
}
|
||||
|
||||
public static bool IsAsyncMethod(MethodBase method)
|
||||
{
|
||||
if (method == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Type attType = typeof(AsyncStateMachineAttribute);
|
||||
var attrib = (AsyncStateMachineAttribute)method.GetCustomAttribute(attType);
|
||||
return (attrib != null);
|
||||
}
|
||||
|
||||
public static StackTraceInfo GetStackTrace()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user