virtualx-engine/modules/mono/glue/Managed/Files/GodotSynchronizationContext.cs

26 lines
786 B
C#
Raw Normal View History

2017-10-02 23:24:00 +02:00
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
namespace Godot
{
2018-09-07 03:08:16 +02:00
public class GodotSynchronizationContext : SynchronizationContext
{
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
2017-10-02 23:24:00 +02:00
2018-09-07 03:08:16 +02:00
public override void Post(SendOrPostCallback d, object state)
{
queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
}
2017-10-02 23:24:00 +02:00
2018-09-07 03:08:16 +02:00
public void ExecutePendingContinuations()
{
KeyValuePair<SendOrPostCallback, object> workItem;
while (queue.TryTake(out workItem))
{
workItem.Key(workItem.Value);
}
}
}
2017-10-02 23:24:00 +02:00
}