TsgcWebSocketServer_HTTPAPI › Methods › ShareList
Acquires a shared (read-only) lock on the internal connection list and returns it for concurrent enumeration.
public TList ShareList();
The live TList of TsgcWSConnection instances held by the server. The caller must treat the list as read-only and must release the lock by calling UnShareList once finished. (TList)
ShareList acquires the list's internal SRW (Slim Reader/Writer) lock in shared mode, allowing multiple threads to enumerate the connection table at the same time without blocking each other. Use it when you only need to read connection state (iterate, count, look up a GUID) — it is significantly cheaper than LockList, which takes the exclusive writer lock and serialises access. Never add, remove or mutate items while holding the shared lock; upgrade to LockList instead. Every call to ShareList must be paired with exactly one call to UnShareList, ideally inside a try..finally block, or the list stays locked and new connections cannot be registered.
TList oList = oServer.ShareList();
try {
for (int i = 0; i < oList.Count; i++)
DoSomething((TsgcWSConnection)oList[i]);
} finally {
oServer.UnShareList();
}