mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] TEngineServer
[+] TEngineServer
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using TEngine.Core.Network;
|
||||
#pragma warning disable CS8765
|
||||
#pragma warning disable CS8601
|
||||
#pragma warning disable CS8618
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public sealed class ThreadSynchronizationContext : SynchronizationContext
|
||||
{
|
||||
public readonly int ThreadId;
|
||||
private Action _actionHandler;
|
||||
private readonly ConcurrentQueue<Action> _queue = new();
|
||||
public static ThreadSynchronizationContext Main { get; } = new(Environment.CurrentManagedThreadId);
|
||||
|
||||
public ThreadSynchronizationContext(int threadId)
|
||||
{
|
||||
ThreadId = threadId;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
while (_queue.TryDequeue(out _actionHandler))
|
||||
{
|
||||
try
|
||||
{
|
||||
_actionHandler();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Post(SendOrPostCallback callback, object state)
|
||||
{
|
||||
Post(() => callback(state));
|
||||
}
|
||||
|
||||
public void Post(Action action)
|
||||
{
|
||||
_queue.Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdf9a97b5cd42dd498c020b421ee8b23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user