Synchronization
Wisej.NET exchanges frequent WebSocket messages with the browser, so thread synchronization matters when handling long-running actions or background tasks that interact with the UI. This page explains which operations Wisej.NET synchronizes and where your code must coordinate access to shared state.
Synchronization Pattern
Wisej.NET synchronizes events received from a client, executing one event at a time in the order received.
If the server takes a long time to process an event, the client may show a gif loader mask blocking the user from interacting with the application. The timing, loader image, and other properties are configurable in Default.json and in the theme.
Refresh requests are not synchronized with the session and are processed in parallel. The user can refresh the browser while the server is processing an event and reload the page at any time.
Data loading requests (DataGrid pulling rows, ListView pulling items) are not synchronized with the session and are processed in parallel. However, they need to lock the collection they are rendering. This feature allows a user to refresh the browser while the server is processing an action and receive back the entire application.
All collections in Wisej.NET are now synchronized at the collection level. It's the tightest possible locking and avoids any possibility of deadlocks since there are no external events in the locked blocks.
Background tasks that need to alter a collection of components owned by a control (i.e. Rows, Items, Child Controls, etc.) may lock the collection itself. Wisej.NET uses the collection instance as the SyncRoot object.
Fair Locking
Ordinary thread locks do not guarantee that waiting threads acquire the lock in the order they began waiting.
Wisej.NET uses a "fair locking" implementation to process waiting threads in order. If a component is disposed while one of its events is waiting to be processed, that event is not executed.
Background Tasks
If your application runs background tasks that interact with UI controls, remember to check if the control has been disposed and lock the collections you are manipulating. If the user closes the application or the parent of a control, the control is disposed and your background task may generate an exception.
Your application remains responsible for synchronizing its own shared state. Wisej.NET synchronizes its internal operations, but that does not automatically protect your application code.