/// <summary> /// Registers a remoted Object with the KeepAlive mechanism of this Class. /// /// @comment Once a remoted Object is Registered, it will be not be GC'ed on the /// PetraServer until it is UnRegistered. /// /// </summary> /// <param name="ARemotedObject">The Remoted Object as an Interface /// </param> /// <returns>void</returns> public static void Register(IKeepAlive ARemotedObject) { try { try { if (Monitor.TryEnter(UKeepAliveObjects.SyncRoot, 10000)) { // Add remoted Object to the SortedList UKeepAliveObjects.Add(ARemotedObject.GetHashCode().ToString(), ARemotedObject); // TLogging.Log("TEnsureKeepAlive.Register: Added Object '" + ARemotedObject.ToString() + "' (HashCode: " + ARemotedObject.GetHashCode().ToString() + ")", TLoggingType.ToLogfile); ARemotedObject.KeepAlive(); } } finally { Monitor.PulseAll(UKeepAliveObjects.SyncRoot); Monitor.Exit(UKeepAliveObjects.SyncRoot); } } catch (Exception Exp) { TLogging.Log("Exception in TEnsureKeepAlive.Register: " + Exp.ToString(), TLoggingType.ToLogfile); } }
internal void Attach(IKeepAlive observer) { _observerDictionary.TryAdd(observer, 0); if (_state == 0) { Init(); } }
/// <summary> /// Unregisters an remoted Object with the KeepAlive mechanism of this Class. /// /// @comment Once an Object is UnRegistered, it will be marked for GC by the /// LeaseManager in the PetraServer as soon as its CurrentLeaseTime gets to /// zero! /// /// </summary> /// <param name="ARemotedObject">The Remoted Object as an Interface /// </param> /// <returns>void</returns> public static void UnRegister(IKeepAlive ARemotedObject) { String ObjectHashCode = string.Empty; if (ARemotedObject != null) { // this is just to not create an Exception... try { ObjectHashCode = ARemotedObject.GetHashCode().ToString(); } catch (System.Runtime.Remoting.RemotingException) { // ignore this Exception: it is thrown if one tries to UnRegister a remoted object that was already UnRegistered and doesn't exist anymore on the PetraServer if (TLogging.DebugLevel > 1) { MessageBox.Show( "Message from TEnsureKeepAlive.UnRegister Method:\r\nAn attempt was made to UnRegister an Object that was already UnRegistered\r\nand doesn't exist anymore on the PetraServer!", "DEVELOPER DEBUGGING INFORMATION"); } } catch (Exception) { } if (ObjectHashCode != "") { try { if (Monitor.TryEnter(UKeepAliveObjects.SyncRoot, 10000)) { if (UKeepAliveObjects.Contains(ObjectHashCode)) { // Remove remoted Object to the SortedList UKeepAliveObjects.Remove(ObjectHashCode); } } } finally { Monitor.PulseAll(UKeepAliveObjects.SyncRoot); Monitor.Exit(UKeepAliveObjects.SyncRoot); } } } }
internal void Detach(IKeepAlive observer) { _observerDictionary.TryRemove(observer, out var _); }