mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-16 16:50:41 +08:00
Asynchronous thread optimization
This commit is contained in:
parent
845dbd99e9
commit
634867d495
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -748,9 +749,18 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IsSingleInstance = true;
|
StackTrace st = new StackTrace(true);
|
||||||
|
var methods = st.GetFrames();
|
||||||
|
var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
|
||||||
|
if (isAsync)
|
||||||
|
{
|
||||||
|
result = Synchronization();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
result = NoSameThread();
|
result = NoSameThread();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (result.Root == null)
|
if (result.Root == null)
|
||||||
{
|
{
|
||||||
result.Root = this;
|
result.Root = this;
|
||||||
|
@ -7,6 +7,7 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@ -44,6 +45,29 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return value;
|
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()
|
public static StackTraceInfo GetStackTrace()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user