/// <summary> /// Register an event to be managed. /// </summary> /// <param name="eventParameters">A <see cref="EventParameters"/> object defining event information.</param> /// <returns>A <see cref="bool"/> value indicating if the event was registered.</returns> public static bool RegisterEvent(EventParameters eventParameters) { if (EventDictionary.Count == MaximumNumberOfEvents) { throw new OverflowException("Can not register another event. The maximum number of events possible to register was reached."); } if (!EventDictionary.TryAdd(eventParameters.GetHashCode(), eventParameters)) { return(false); } if (s_eventTask.Status == TaskStatus.Created) { s_eventTask.Start(); } else if (s_eventTask.IsCompleted) { s_eventTask = Task.Run(EventLoop); } return(true); }
/// <summary> /// Unregisters an event from the event manager. The <see cref="EventParameters"/> instance must be the same instance as the event was registered with. /// </summary> /// <param name="eventParameters">A <see cref="EventParameters"/> object defining event information.</param> /// <returns>A <see cref="bool"/> value indicating if the event was unregistered.</returns> public static bool UnregisterEvent(EventParameters eventParameters) { return(EventDictionary.TryRemove(eventParameters.GetHashCode(), out eventParameters)); }