1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Threading;
- namespace YooAsset
- {
-
-
-
-
- internal sealed class ThreadSyncContext : SynchronizationContext
- {
- private readonly ConcurrentQueue<Action> _safeQueue = new ConcurrentQueue<Action>();
-
-
-
- public void Update()
- {
- while (true)
- {
- if (_safeQueue.TryDequeue(out Action action) == false)
- return;
- action.Invoke();
- }
- }
-
-
-
- public override void Post(SendOrPostCallback callback, object state)
- {
- Action action = new Action(() => { callback(state); });
- _safeQueue.Enqueue(action);
- }
- }
- }
|