OBT/1.0.14
Fixed parallelism count issue Added SingleThreadWorker to handle single-thread related works Fixed incorrect order when updating gaps Potentially Fixed #39
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public class SingleThreadWorker
|
||||
{
|
||||
private ConcurrentQueue<Action> ActionQueue;
|
||||
|
||||
public static SingleThreadWorker GlobalWorker = new SingleThreadWorker();
|
||||
|
||||
public SingleThreadWorker()
|
||||
{
|
||||
ActionQueue = new ConcurrentQueue<Action>();
|
||||
}
|
||||
|
||||
public void AddAction(Action action)
|
||||
{
|
||||
ActionQueue.Enqueue(action);
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
public void RunActions()
|
||||
{
|
||||
while (ActionQueue.TryDequeue(out Action action))
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Just try-catch and do nothing but print errorlogs. We cannot afford crashing the game.
|
||||
ConsoleColor originalForeground = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"WARNING: Error occurred when running Single Thread Actions \n{e}");
|
||||
Console.ForegroundColor = Console.ForegroundColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user