Beispiel #1
0
        /// <summary>
        ///     Adds the specified <see cref="ICadencedControl" /> to the list of managed controls. If this is the first
        ///     <paramref name="control" /> being added, then the update timer is configured and started.
        /// </summary>
        /// <remarks>
        ///     Each <paramref name="control" /> can only appear in the list once (duplicate adds will be silently
        ///     ignored).
        /// </remarks>
        /// <param name="control">The control to be managed.</param>
        public void Add(ICadencedControl control)
        {
            var hashCode = control.GetHashCode();

            Trace.WriteLine($"Adding hash {hashCode}");
            if (ControlList.ContainsKey(hashCode))
            {
                Trace.TraceWarning($"Ignoring duplicate hash code {hashCode}.");
            }
            else
            {
                ControlList.Add(hashCode, new WeakReference <ICadencedControl>(control));
            }
            if (updateTask == null)
            {
                StartUpdates();
            }
        }
Beispiel #2
0
 /// <summary>
 ///     Removes a <paramref name="control" /> from the
 ///     <see cref="TA.WinFormsControls.CadencedControlUpdater.ControlList" /> . If no managed controls remain in
 ///     the list, then the update timer is stopped.
 /// </summary>
 public void Remove(ICadencedControl control)
 {
     try
     {
         var hash = control.GetHashCode();
         Trace.TraceInformation($"Removing hash {hash}");
         if (ControlList.ContainsKey(hash))
         {
             ControlList.Remove(hash);
         }
     }
     catch (Exception e)
     {
         Trace.TraceError($"{e.GetType().Name} removing control: {e.Message}");
     }
     finally
     {
         if (!ControlList?.Any() ?? false)
         {
             StopUpdates();
         }
     }
 }