Interface ITaskQueue
- Namespace
- SkyrimForge
- Assembly
- SkyrimForge.dll
Queues work to run at a moment the game is stopped for it, which is how a plugin calls the game from a thread of its own.
public interface ITaskQueue
Remarks
SKSE picks the thread, one of the game's worker threads and never the game's thread. The game being stopped makes the work safe, rather than the thread it runs on. Work that blocks until the game's thread runs never finishes, because the game's thread is waiting for that work. BGSSaveLoadManager.Save on Skyrim VR is an example: called from queued work it returned false once and blocked once, and called on the game's thread it saved. SKSE picks the thread again for each piece, so no thread-local value survives between pieces and a lock acquired in one cannot be released in the next. The game waits throughout, so long work costs frames. Queued work never runs at the same time as code on the game's thread, and queued pieces, from either queue, run one at a time, so a member documented as called on the game's thread may be called from queued work.
A handler on the game's thread calls the game directly. A handler on a worker thread runs at the same time as handlers on the others, so the work in it that changes the game, or calls a member documented as called on the game's thread, is queued here. That work can instead follow an await of WaitForGameThreadAsync(IUtility, CancellationToken). IGameEvents states which events are raised where. A task a framework member returns completes on the game's thread or in queued work, so the code after awaiting it may call a member documented as called on the game's thread. The exception is SetAsync(QuestStage) and SetAsync(): for a stage with a OnSet, the task completes where the task OnSet returns completes.
Methods
AddTask(Action)
Queues work to run at the next point the game stops for it.
void AddTask(Action work)
Parameters
workActionThe work to run. An exception it throws is written to the log of the plugin that queued it.
Exceptions
- ArgumentNullException
workisnull.
AddUITask(Action)
Queues work to run while the game updates its interface.
void AddUITask(Action work)
Parameters
workActionThe work to run. An exception it throws is written to the log of the plugin that queued it.
Exceptions
- ArgumentNullException
workisnull.