Async MainThrad Helper Function
C#: Helper.cs
using GTANetworkAPI;
using System;
using System.Text;
using System.Threading.Tasks;
namespace MeinServer.Helper
{
public class Utils
{
public static async Task RunFromAsyncContext(Action action)
{
if (System.Threading.Thread.CurrentThread.ManagedThreadId == NAPI.MainThreadId)
{
action();
}
else
{
NAPI.Task.Run(action);
await NAPI.Task.WaitForMainThread();
}
}
}
}
Alles anzeigen
Nutzungs Beispiel: