Files
sbox-public/engine/Sandbox.Engine/Systems/Networking/Networking.Thread.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

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" );
}
}
}