--- name: sws2-thread-management description: Keep SwiftlyS2 game operations on the game thread while coordinating async/await, Task.Run, background I/O such as HTTP and database calls, Core.Scheduler NextTick and NextWorldUpdate callbacks, delays, repeating timers and their cancellation across disconnects, map changes and hot reloads. Use whenever plugin code awaits, starts a task, schedules or delays work, uses a timer, or hits a crash or exception from calling game APIs off the game thread. --- Read [dispatch and lifetime](references/threads.md) when work crosses an `await`, background task, tick, or map boundary. Use `Core.IsGameThread` and API thread annotations to choose the execution context. Don't pass `async` lambdas to `void`-returning handlers; start I/O with `Task.Run` and never block the game thread on a task. Complete I/O outside the game thread, then schedule a synchronous callback or use a documented async game API. Resolve current players and entities inside the callback. Keep timers and deferred work within their plugin and map lifetime. Verify scheduler overloads through SwiftlyS2 MCP for the target runtime. Build and exercise the async route, including disconnect, map change, and hot reload when they affect the feature.