| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- using Thread = Internal.Runtime.Augments.RuntimeThread;
- namespace System.Threading
- {
- public partial class SynchronizationContext
- {
- private bool _requireWaitNotification;
- public SynchronizationContext()
- {
- }
- #if !FEATURE_APPX && !ENABLE_WINRT
- public static SynchronizationContext Current => Thread.CurrentThread.SynchronizationContext;
- #endif
- protected void SetWaitNotificationRequired() => _requireWaitNotification = true;
- public bool IsWaitNotificationRequired() => _requireWaitNotification;
- public virtual void Send(SendOrPostCallback d, object state) => d(state);
- public virtual void Post(SendOrPostCallback d, object state) => ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false);
- /// <summary>
- /// Optional override for subclasses, for responding to notification that operation is starting.
- /// </summary>
- public virtual void OperationStarted()
- {
- }
- /// <summary>
- /// Optional override for subclasses, for responding to notification that operation has completed.
- /// </summary>
- public virtual void OperationCompleted()
- {
- }
- [CLSCompliant(false)]
- public virtual int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
- {
- return WaitHelper(waitHandles, waitAll, millisecondsTimeout);
- }
- [CLSCompliant(false)]
- protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
- {
- if (waitHandles == null)
- {
- throw new ArgumentNullException(nameof(waitHandles));
- }
- return WaitHandle.WaitMultipleIgnoringSyncContext(waitHandles, waitAll, millisecondsTimeout);
- }
- public static void SetSynchronizationContext(SynchronizationContext syncContext) => Thread.CurrentThread.SynchronizationContext = syncContext;
- public virtual SynchronizationContext CreateCopy() => new SynchronizationContext();
- }
- }
|