mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-05 04:48:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
54 lines
790 B
C#
54 lines
790 B
C#
using System.Threading;
|
|
|
|
namespace Sandbox;
|
|
|
|
public static partial class Networking
|
|
{
|
|
private static bool _isClosing;
|
|
|
|
internal static void StartThread()
|
|
{
|
|
_isClosing = false;
|
|
|
|
var thread = new Thread( RunThread )
|
|
{
|
|
Name = "Networking (managed)",
|
|
Priority = ThreadPriority.AboveNormal
|
|
};
|
|
|
|
thread.Start();
|
|
}
|
|
|
|
internal static void StopThread()
|
|
{
|
|
_isClosing = true;
|
|
}
|
|
|
|
static Lock NetworkThreadLock = new Lock();
|
|
|
|
private static void RunThread()
|
|
{
|
|
try
|
|
{
|
|
while ( !_isClosing )
|
|
{
|
|
var system = System;
|
|
|
|
if ( system is not null )
|
|
{
|
|
lock ( NetworkThreadLock )
|
|
{
|
|
system.ProcessMessagesInThread();
|
|
}
|
|
}
|
|
|
|
Thread.Sleep( 1 );
|
|
}
|
|
}
|
|
catch ( System.Exception e )
|
|
{
|
|
Log.Error( e, "Network Thread Error" );
|
|
}
|
|
}
|
|
}
|