10 [__DynamicallyInvokable]
14 private delegate
int WaitDelegate(
IntPtr[] waitHandles,
bool waitAll,
int millisecondsTimeout);
16 private SynchronizationContextProperties _props;
18 private static Type s_cachedPreparedType1;
20 private static Type s_cachedPreparedType2;
22 private static Type s_cachedPreparedType3;
24 private static Type s_cachedPreparedType4;
26 private static Type s_cachedPreparedType5;
29 private static WinRTSynchronizationContextFactoryBase s_winRTContextFactory;
33 [__DynamicallyInvokable]
36 [__DynamicallyInvokable]
39 return Thread.
CurrentThread.GetExecutionContextReader().SynchronizationContext ?? GetThreadLocalContext();
48 return Thread.
CurrentThread.GetExecutionContextReader().SynchronizationContextNoFlow ?? GetThreadLocalContext();
53 [__DynamicallyInvokable]
59 [SecuritySafeCritical]
62 Type type = GetType();
63 if (s_cachedPreparedType1 != type && s_cachedPreparedType2 != type && s_cachedPreparedType3 != type && s_cachedPreparedType4 != type && s_cachedPreparedType5 != type)
66 if (s_cachedPreparedType1 ==
null)
68 s_cachedPreparedType1 = type;
70 else if (s_cachedPreparedType2 ==
null)
72 s_cachedPreparedType2 = type;
74 else if (s_cachedPreparedType3 ==
null)
76 s_cachedPreparedType3 = type;
78 else if (s_cachedPreparedType4 ==
null)
80 s_cachedPreparedType4 = type;
82 else if (s_cachedPreparedType5 ==
null)
84 s_cachedPreparedType5 = type;
87 _props |= SynchronizationContextProperties.RequireWaitNotification;
95 return (_props & SynchronizationContextProperties.RequireWaitNotification) != SynchronizationContextProperties.None;
102 [__DynamicallyInvokable]
111 [__DynamicallyInvokable]
118 [__DynamicallyInvokable]
124 [__DynamicallyInvokable]
138 [CLSCompliant(
false)]
140 public virtual int Wait(
IntPtr[] waitHandles,
bool waitAll,
int millisecondsTimeout)
142 if (waitHandles ==
null)
146 return WaitHelper(waitHandles, waitAll, millisecondsTimeout);
157 [CLSCompliant(
false)]
159 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
160 protected static extern int WaitHelper(
IntPtr[] waitHandles,
bool waitAll,
int millisecondsTimeout);
165 [__DynamicallyInvokable]
169 mutableExecutionContext.SynchronizationContext = syncContext;
170 mutableExecutionContext.SynchronizationContextNoFlow = syncContext;
176 if (synchronizationContext ==
null &&
Environment.IsWinRTSupported)
178 synchronizationContext = GetWinRTContext();
180 return synchronizationContext;
183 [SecuritySafeCritical]
186 if (!AppDomain.IsAppXModel())
190 object winRTDispatcherForCurrentThread = GetWinRTDispatcherForCurrentThread();
191 if (winRTDispatcherForCurrentThread !=
null)
193 return GetWinRTSynchronizationContextFactory().Create(winRTDispatcherForCurrentThread);
199 private static WinRTSynchronizationContextFactoryBase GetWinRTSynchronizationContextFactory()
201 WinRTSynchronizationContextFactoryBase winRTSynchronizationContextFactoryBase = s_winRTContextFactory;
202 if (winRTSynchronizationContextFactoryBase ==
null)
204 Type type =
Type.GetType(
"System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", throwOnError:
true);
205 winRTSynchronizationContextFactoryBase = (s_winRTContextFactory = (WinRTSynchronizationContextFactoryBase)Activator.CreateInstance(type, nonPublic:
true));
207 return winRTSynchronizationContextFactoryBase;
212 [SuppressUnmanagedCodeSecurity]
214 private static extern object GetWinRTDispatcherForCurrentThread();
218 [__DynamicallyInvokable]
225 private static int InvokeWaitMethodHelper(
SynchronizationContext syncContext,
IntPtr[] waitHandles,
bool waitAll,
int millisecondsTimeout)
227 return syncContext.
Wait(waitHandles, waitAll, millisecondsTimeout);
static Thread CurrentThread
Gets the currently running thread.
virtual void Post(SendOrPostCallback d, object state)
When overridden in a derived class, dispatches an asynchronous message to a synchronization context.
virtual void Send(SendOrPostCallback d, object state)
When overridden in a derived class, dispatches a synchronous message to a synchronization context.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
static SynchronizationContext?? Current
Gets the synchronization context for the current thread.
delegate void SendOrPostCallback(object state)
Represents a method to be called when a message is to be dispatched to a synchronization context.
static bool QueueUserWorkItem(WaitCallback callBack, object state)
Queues a method for execution, and specifies an object containing data to be used by the method....
void SetWaitNotificationRequired()
Sets notification that wait notification is required and prepares the callback method so it can be ca...
virtual int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
Waits for any or all the elements in the specified array to receive a signal.
static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
Helper function that waits for any or all the elements in the specified array to receive a signal.
Cer
Specifies a method's behavior when called within a constrained execution region.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Manages the execution context for the current thread. This class cannot be inherited.
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
bool IsWaitNotificationRequired()
Determines if wait notification is required.
SynchronizationContext()
Creates a new instance of the T:System.Threading.SynchronizationContext class.
A platform-specific type that is used to represent a pointer or a handle.
Provides the basic functionality for propagating a synchronization context in various synchronization...
virtual void OperationCompleted()
When overridden in a derived class, responds to the notification that an operation has completed.
Represents type declarations: class types, interface types, array types, value types,...
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
virtual SynchronizationContext CreateCopy()
When overridden in a derived class, creates a copy of the synchronization context.
static void SetSynchronizationContext(SynchronizationContext syncContext)
Sets the current synchronization context.
virtual void OperationStarted()
When overridden in a derived class, responds to the notification that an operation has started.
Consistency
Specifies a reliability contract.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Provides a set of static methods and properties that provide support for compilers....
Creates and controls a thread, sets its priority, and gets its status.
static void PrepareDelegate(Delegate d)
Indicates that the specified delegate should be prepared for inclusion in a constrained execution reg...