Przeglądaj źródła

Fix memory leak in job reconciliation menu.

Gregory 3 lat temu
rodzic
commit
9eefe23aeb
1 zmienionych plików z 15 dodań i 5 usunięć
  1. 15 5
      crusherScanner/Form1.cs

+ 15 - 5
crusherScanner/Form1.cs

@@ -35,6 +35,7 @@ namespace crusherScanner
             TextBox1.Focus();
             Logging.Append(LogLevel.Information,"Crusher Scanner Application " + Application.ProductVersion + " has started.");
             notifyIcon1.ShowBalloonTip(30, "Crusher Scanner Application", "Crusher Scanner Application, version " + Application.ProductVersion + " has started.", System.Windows.Forms.ToolTipIcon.Info);
+            Logging.Append(LogLevel.Debug, "Starting Reconciliation checks.");
             backgroundWorker2.RunWorkerAsync();
         }
 
@@ -90,8 +91,15 @@ namespace crusherScanner
                     toolStripStatusLabel2.Text = scanned.BufferCount.ToString();
                     Logging.Append(LogLevel.Debug, $"{scanned.BufferCount} samples in the Ore Def buffer.");
                 }
-
-                backgroundWorker2.RunWorkerAsync();
+                if (!backgroundWorker2.IsBusy)
+                {
+                    Logging.Append(LogLevel.Debug, "Starting Reconciliation checks.");
+                    backgroundWorker2.RunWorkerAsync();
+                }
+                else
+                {
+                    Logging.Append(LogLevel.Debug, "Did not start Reconciliation checks (Job already in progress).");
+                }
             }
         }
 
@@ -271,6 +279,7 @@ namespace crusherScanner
 
         private void backgroundWorker2_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
         {
+            reconciliationToolStripMenuItem.DropDownItems.Clear();
             if (e.Result != null)
             {
                 var data = (HashSet<string>)e.Result;
@@ -285,16 +294,17 @@ namespace crusherScanner
                         reconciliationToolStripMenuItem.DropDownItems.Add(reconList);
                     }
                 }
+                Logging.Append(LogLevel.Debug, $"{data.Count} job(s) pending Reconciliation.");
             }
+            Logging.Append(LogLevel.Debug, "Reconciliation checks completed.");
         }
         
         private void FileMenuItemClick(object? sender, EventArgs e)
-        {
+        {            
             string path = Properties.Settings.Default.OreDefWorkFile;
-            var missingSamples = new HashSet<string>();
             if (sender!=null)
             {
-                missingSamples = Reconciliation.CheckJobReconcilableDiscrepencies($"{path}\\{sender}");
+                HashSet<string> missingSamples = Reconciliation.CheckJobReconcilableDiscrepencies($"{path}\\{sender}");
                 if (missingSamples.Count >= 1)
                 {
                     int widthCounter = 0;