// 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); /// /// Optional override for subclasses, for responding to notification that operation is starting. /// public virtual void OperationStarted() { } /// /// Optional override for subclasses, for responding to notification that operation has completed. /// 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(); } }