diff --git a/Torch/Event/EventList.cs b/Torch/Event/EventList.cs index 28bcf33..8a1a2e8 100644 --- a/Torch/Event/EventList.cs +++ b/Torch/Event/EventList.cs @@ -75,11 +75,6 @@ namespace Torch.Event removeCount++; i--; } - if (removeCount > 0) - { - _dispatchersDirty = true; - _dispatchers.RemoveRange(_dispatchers.Count - removeCount, removeCount); - } return removeCount; } finally diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs index eaccab9..886376d 100644 --- a/Torch/TorchBase.cs +++ b/Torch/TorchBase.cs @@ -231,6 +231,14 @@ namespace Torch [MethodImpl(MethodImplOptions.NoInlining)] public void InvokeBlocking(Action action, int timeoutMs = -1, [CallerMemberName] string caller = "") { + if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread) + { + Debug.Assert(false, $"{nameof(InvokeBlocking)} should not be called on the game thread."); + // ReSharper disable once HeuristicUnreachableCode + action.Invoke(); + return; + } + // ReSharper disable once ExplicitCallerInfoArgument Task task = InvokeAsync(action, caller); if (!task.Wait(timeoutMs)) @@ -243,19 +251,6 @@ namespace Torch [MethodImpl(MethodImplOptions.NoInlining)] public Task InvokeAsync(Func action, [CallerMemberName] string caller = "") { - if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread) - { - Debug.Assert(false, $"{nameof(InvokeAsync)} should not be called on the game thread."); - // ReSharper disable once HeuristicUnreachableCode - try - { - return Task.FromResult(action.Invoke()); - } - catch (Exception e) - { - return Task.FromException(e); - } - } var ctx = new TaskCompletionSource(); MySandboxGame.Static.Invoke(() => { @@ -273,28 +268,12 @@ namespace Torch } }, caller); return ctx.Task; - } - /// [MethodImpl(MethodImplOptions.NoInlining)] public Task InvokeAsync(Action action, [CallerMemberName] string caller = "") { - if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread) - { - Debug.Assert(false, $"{nameof(InvokeAsync)} should not be called on the game thread."); - // ReSharper disable once HeuristicUnreachableCode - try - { - action.Invoke(); - return Task.CompletedTask; - } - catch (Exception e) - { - return Task.FromException(e); - } - } var ctx = new TaskCompletionSource(); MySandboxGame.Static.Invoke(() => {