From 923d6437b82219cc98bfcb4d745355bf77e3eb85 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 31 Dec 2020 01:57:22 +0000 Subject: [PATCH] smartthreadpool: replace thread context code to use ExecutionContext --- .../SmartThreadPool/CallerThreadContext.cs | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 ThirdParty/SmartThreadPool/CallerThreadContext.cs diff --git a/ThirdParty/SmartThreadPool/CallerThreadContext.cs b/ThirdParty/SmartThreadPool/CallerThreadContext.cs deleted file mode 100644 index d8c65a9727..0000000000 --- a/ThirdParty/SmartThreadPool/CallerThreadContext.cs +++ /dev/null @@ -1,97 +0,0 @@ - -using System; -using System.Diagnostics; -using System.Threading; -using System.Reflection; -using System.Web; -using System.Runtime.Remoting.Messaging; - - -namespace Amib.Threading.Internal -{ - #region CallerThreadContext class - - /// - /// This class stores the caller call context in order to restore - /// it when the work item is executed in the thread pool environment. - /// - internal class CallerThreadContext - { - #region Prepare reflection information - - // Cached type information. - private static readonly MethodInfo getLogicalCallContextMethodInfo = - typeof(Thread).GetMethod("GetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); - - private static readonly MethodInfo setLogicalCallContextMethodInfo = - typeof(Thread).GetMethod("SetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); - - #endregion - - #region Private fields - - private LogicalCallContext _callContext; - - #endregion - - /// - /// Constructor - /// - private CallerThreadContext() - { - } - - public bool CapturedCallContext - { - get - { - return (null != _callContext); - } - } - - /// - /// Captures the current thread context - /// - /// - public static CallerThreadContext Capture(bool captureCallContext) - { - Debug.Assert(captureCallContext); - - CallerThreadContext callerThreadContext = new CallerThreadContext(); - - // TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture() - // Capture Call Context - if (captureCallContext && (getLogicalCallContextMethodInfo != null)) - { - callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null); - if (callerThreadContext._callContext != null) - { - callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone(); - } - } - - return callerThreadContext; - } - - /// - /// Applies the thread context stored earlier - /// - /// - public static void Apply(CallerThreadContext callerThreadContext) - { - if (null == callerThreadContext) - { - throw new ArgumentNullException("callerThreadContext"); - } - - // Todo: In NET 2.0, redo using the new feature of ExecutionContext class - Run() - // Restore call context - if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null)) - { - setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext }); - } - } - } - - #endregion -}