blob: 687c786dc6f41670be1a23c68e908851f0c40673 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Threading;
namespace System.Windows.Threading
{
public sealed class DispatcherSynchronizationContext : SynchronizationContext
{
readonly Dispatcher dispatcher;
readonly DispatcherPriority priority;
public DispatcherSynchronizationContext(Dispatcher dispatcher, DispatcherPriority priority)
{
this.dispatcher = dispatcher
?? throw new ArgumentNullException(nameof(dispatcher));
this.priority = priority;
}
public DispatcherSynchronizationContext(Dispatcher dispatcher) : this(dispatcher, DispatcherPriority.Normal)
{
}
public DispatcherSynchronizationContext() : this(Dispatcher.CurrentDispatcher)
{
}
public override SynchronizationContext CreateCopy()
=> new DispatcherSynchronizationContext(dispatcher, priority);
public override void Post(SendOrPostCallback d, object state)
=> dispatcher.BeginInvoke(d, priority, state);
public override void Send(SendOrPostCallback d, object state)
=> dispatcher.Invoke(() => d(state), priority);
}
}
|