diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-04-01 18:29:35 -0400 |
---|---|---|
committer | Dan Moseley <danmose@microsoft.com> | 2019-04-01 15:29:35 -0700 |
commit | f406d721bc1edaa6fa842f14e262b74ea3fa4d4e (patch) | |
tree | 167277bafdb2b98b7a78e03761d1a8a256d6cdb0 /src/System.Private.CoreLib/src/System/Threading | |
parent | af2fd41ca67da6c90dea190cc9df5d9ebb0ea973 (diff) | |
download | coreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.tar.gz coreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.tar.bz2 coreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.zip |
Nullable: SynchronizationContext (#23634)
Diffstat (limited to 'src/System.Private.CoreLib/src/System/Threading')
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs | 1 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs | 19 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs index e26d9b7b70..db110279db 100644 --- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable namespace System.Threading { public partial class SynchronizationContext diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs index a9f0727771..b04f93e516 100644 --- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs +++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Reflection; @@ -11,11 +12,11 @@ namespace System.Threading { public partial class SynchronizationContext { - public static SynchronizationContext Current + public static SynchronizationContext? Current { get { - SynchronizationContext context = Thread.CurrentThread._synchronizationContext; + SynchronizationContext? context = Thread.CurrentThread._synchronizationContext; if (context == null && ApplicationModel.IsUap) context = GetWinRTContext(); @@ -24,7 +25,7 @@ namespace System.Threading } } - private static SynchronizationContext GetWinRTContext() + private static SynchronizationContext? GetWinRTContext() { Debug.Assert(Environment.IsWinRTSupported); Debug.Assert(ApplicationModel.IsUap); @@ -39,14 +40,14 @@ namespace System.Threading // So, we check the VM to see if the current thread has a dispatcher; if it does, we pass that along to // System.Runtime.WindowsRuntime to get a corresponding SynchronizationContext. // - object dispatcher = GetWinRTDispatcherForCurrentThread(); + object? dispatcher = GetWinRTDispatcherForCurrentThread(); if (dispatcher != null) return GetWinRTSynchronizationContext(dispatcher); return null; } - private static Func<object, SynchronizationContext> s_createSynchronizationContextDelegate; + private static Func<object, SynchronizationContext>? s_createSynchronizationContextDelegate; private static SynchronizationContext GetWinRTSynchronizationContext(object dispatcher) { @@ -55,23 +56,23 @@ namespace System.Threading // 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. // - Func<object, SynchronizationContext> createSynchronizationContextDelegate = s_createSynchronizationContextDelegate; + Func<object, SynchronizationContext>? createSynchronizationContextDelegate = s_createSynchronizationContextDelegate; if (createSynchronizationContextDelegate == null) { Type factoryType = Type.GetType("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime", throwOnError: true); // Create an instance delegate for the Create static method MethodInfo createMethodInfo = factoryType.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); - createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo, /* throwOnBindFailure */ true); + createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo); s_createSynchronizationContextDelegate = createSynchronizationContextDelegate; } - return s_createSynchronizationContextDelegate(dispatcher); + return createSynchronizationContextDelegate(dispatcher); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [return: MarshalAs(UnmanagedType.Interface)] - private static extern object GetWinRTDispatcherForCurrentThread(); + private static extern object? GetWinRTDispatcherForCurrentThread(); } } |