diff ServerMonitor/Objects/ServerMonitor.cs @ 28:437442cd8090

Fix checks still running after a server is deleted and checks not running immediately after a server is created.
author Brad Greco <brad@bgreco.net>
date Sun, 02 Jun 2019 17:55:38 -0400
parents 781d8b980be1
children f6235dc0a8ec
line wrap: on
line diff
--- a/ServerMonitor/Objects/ServerMonitor.cs	Sun Jun 02 17:51:30 2019 -0400
+++ b/ServerMonitor/Objects/ServerMonitor.cs	Sun Jun 02 17:55:38 2019 -0400
@@ -67,6 +67,8 @@
         {
             Servers.Add(server);
             SaveServers();
+            server.CheckModified += Server_CheckModified;
+            server.EnabledChanged += Server_EnabledChanged;
         }
 
         /// <summary>Deletes a server from the server monitor.</summary>
@@ -74,6 +76,12 @@
         public void DeleteServer(Server server)
         {
             Servers.Remove(server);
+            // Cancel all queued and executing checks belonging to a
+            // server that was deleted.
+            foreach (Check check in server.Checks)
+            {
+                CancelCheck(check);
+            }
             SaveServers();
         }