/// <summary> /// Checks if the <see cref="SynchronizedObject"/> is still in use /// by at least one client. If this is not the case it is disposed /// so that the associated object is no longer tracked. /// </summary> /// <param name="o">Synchronized object</param> internal void CleanUpSynchronizedObject(SynchronizedObject o) { lock (_lock) { if (!o.ConnectedClients.Any()) { o.Dispose(); _syncedObjects.Remove(o.Object); } } }
/// <summary> /// Returns the single <see cref="SynchronizedObject"/> instance /// for the hub that is used to synchronize the specified object. /// </summary> /// <remarks> /// If an object is synchronized with multiple clients we only /// want to maintain one <see cref="SynchronizedObject"/> instance /// (and only one <see cref="ObjectTracker"/>) for that object. /// </remarks> /// <param name="o">Object</param> /// <returns></returns> internal SynchronizedObject GetSynchronizedObject(object o) { lock (_lock) { SynchronizedObject syncedObject; if (_syncedObjects.TryGetValue(o, out syncedObject)) { // Return existing SynchronizedObject return(syncedObject); } else { // Create new SynchronizedObject syncedObject = new SynchronizedObject(_syncHub, o); _syncedObjects.Add(o, syncedObject); return(syncedObject); } } }