mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-07-15 05:13:18 +08:00
41 lines
791 B
C#
41 lines
791 B
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace CPF.Mac.CoreFoundation
|
|
{
|
|
internal sealed class DispatchQueueSynchronizationContext : SynchronizationContext
|
|
{
|
|
private readonly DispatchQueue queue;
|
|
|
|
public DispatchQueueSynchronizationContext(DispatchQueue dispatchQueue)
|
|
{
|
|
if (dispatchQueue == null)
|
|
{
|
|
throw new ArgumentNullException("dispatchQueue");
|
|
}
|
|
queue = dispatchQueue;
|
|
}
|
|
|
|
public override SynchronizationContext CreateCopy()
|
|
{
|
|
return new DispatchQueueSynchronizationContext(queue);
|
|
}
|
|
|
|
public override void Post(SendOrPostCallback d, object state)
|
|
{
|
|
queue.DispatchAsync(delegate
|
|
{
|
|
d(state);
|
|
});
|
|
}
|
|
|
|
public override void Send(SendOrPostCallback d, object state)
|
|
{
|
|
queue.DispatchSync(delegate
|
|
{
|
|
d(state);
|
|
});
|
|
}
|
|
}
|
|
}
|