using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEditor;
namespace UnityTcp.Editor.Helpers
{
///
/// Helper class for main thread operations
///
public static class MainThreadHelper
{
private static int mainThreadId;
///
/// Initialize the main thread ID for safe thread checks
/// Call this from the main thread during static constructor
///
public static void InitializeMainThreadId()
{
try { mainThreadId = Thread.CurrentThread.ManagedThreadId; } catch { mainThreadId = 0; }
}
///
/// Invoke the given function on the Unity main thread and wait up to timeoutMs for the result.
/// Returns null on timeout or error; caller should provide a fallback error response.
///
public static object InvokeOnMainThreadWithTimeout(Func