diff --git a/Dalamud/Utility/ThreadSafety.cs b/Dalamud/Utility/ThreadSafety.cs index c31cc0005..7ce6a0776 100644 --- a/Dalamud/Utility/ThreadSafety.cs +++ b/Dalamud/Utility/ThreadSafety.cs @@ -1,5 +1,7 @@ using System.Runtime.CompilerServices; +using Dalamud.Game; + namespace Dalamud.Utility; /// @@ -23,7 +25,9 @@ public static class ThreadSafety [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AssertMainThread(string? message = null) { - if (!threadStaticIsMainThread) + var isFrameworkUnloading = Service.GetNullable()?.IsFrameworkUnloading ?? true; + + if (!threadStaticIsMainThread && !isFrameworkUnloading) { throw new InvalidOperationException(message ?? "Not on main thread!"); } @@ -36,7 +40,9 @@ public static class ThreadSafety [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AssertNotMainThread() { - if (threadStaticIsMainThread) + var isFrameworkUnloading = Service.GetNullable()?.IsFrameworkUnloading ?? true; + + if (threadStaticIsMainThread && !isFrameworkUnloading) { throw new InvalidOperationException("On main thread!"); }