From: Luqun Lou Date: Mon, 11 Jun 2018 18:29:46 +0000 (-0700) Subject: Remove WinRTSynchronizationContextFactoryBase (#18385) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77a0f349aff937a8e16bc6fd1b52117d845e1fae;p=platform%2Fupstream%2Fcoreclr.git Remove WinRTSynchronizationContextFactoryBase (#18385) --- diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs index f438e9a03d..c7c588635b 100644 --- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs +++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs @@ -32,17 +32,6 @@ namespace System.Threading RequireWaitNotification = 0x1 }; -#if FEATURE_COMINTEROP && FEATURE_APPX - // - // This is implemented in System.Runtime.WindowsRuntime, allowing us to ask that assembly for a WinRT-specific SyncCtx. - // - // [FriendAccessAllowed] - internal abstract class WinRTSynchronizationContextFactoryBase - { - public abstract SynchronizationContext Create(object coreDispatcher); - } -#endif //FEATURE_COMINTEROP - public class SynchronizationContext { private SynchronizationContextProperties _props = SynchronizationContextProperties.None; @@ -189,27 +178,33 @@ namespace System.Threading // object dispatcher = GetWinRTDispatcherForCurrentThread(); if (dispatcher != null) - return GetWinRTSynchronizationContextFactory().Create(dispatcher); + return GetWinRTSynchronizationContext(dispatcher); return null; } - private static WinRTSynchronizationContextFactoryBase s_winRTContextFactory; + private static Func s_createSynchronizationContextDelegate = null; - private static WinRTSynchronizationContextFactoryBase GetWinRTSynchronizationContextFactory() + private static SynchronizationContext GetWinRTSynchronizationContext(object dispatcher) { // // Since we can't directly reference System.Runtime.WindowsRuntime from mscorlib, we have to get the factory via reflection. // It would be better if we could just implement WinRTSynchronizationContextFactory in mscorlib, but we can't, because // we can do very little with WinRT stuff in mscorlib. // - WinRTSynchronizationContextFactoryBase factory = s_winRTContextFactory; - if (factory == null) + Func createSynchronizationContextDelegate = s_createSynchronizationContextDelegate; + if (createSynchronizationContextDelegate == null) { Type factoryType = Type.GetType("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime", throwOnError: true); - s_winRTContextFactory = factory = (WinRTSynchronizationContextFactoryBase)Activator.CreateInstance(factoryType, true); + + // Create an instance delegate for the Create static method + MethodInfo createMethodInfo = factoryType.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); + createSynchronizationContextDelegate = (Func)Delegate.CreateDelegate(typeof(Func), createMethodInfo, /* throwOnBindFailure */ true); + + s_createSynchronizationContextDelegate = createSynchronizationContextDelegate; } - return factory; + + return s_createSynchronizationContextDelegate(dispatcher); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]