diff --git a/PartPreviewWindow/GcodeViewBasic.cs b/PartPreviewWindow/GcodeViewBasic.cs index 52ce0dc97..2d597d6a7 100644 --- a/PartPreviewWindow/GcodeViewBasic.cs +++ b/PartPreviewWindow/GcodeViewBasic.cs @@ -145,7 +145,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // we only hook these up to make sure we can regenerate the gcode when we want printItem.SlicingOutputMessage += sliceItem_SlicingOutputMessage; - printItem.Done += new EventHandler(sliceItem_Done); + printItem.Done += sliceItem_Done; } centerPartPreviewAndControls.AddChild(gcodeDispalyWidget); @@ -622,6 +622,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow void sliceItem_Done(object sender, EventArgs e) { + // We can add this while we have it open (when we are done loading). + // So we need to make sure we only have it added once. This will be ok to run when + // not added or when added and will ensure we only have one hook. + printItem.SlicingOutputMessage -= sliceItem_SlicingOutputMessage; + printItem.Done -= sliceItem_Done; + UiThread.RunOnIdle(CreateAndAddChildren); startedSliceFromGenerateButton = false; } diff --git a/PrintQueue/ExportToFolderProcess.cs b/PrintQueue/ExportToFolderProcess.cs index 835077283..5ff047e95 100644 --- a/PrintQueue/ExportToFolderProcess.cs +++ b/PrintQueue/ExportToFolderProcess.cs @@ -101,6 +101,7 @@ namespace MatterHackers.MatterControl.PrintQueue PrintItemWrapper sliceItem = (PrintItemWrapper)sender; sliceItem.Done -= new EventHandler(sliceItem_Done); + sliceItem.SlicingOutputMessage -= printItemWrapper_SlicingOutputMessage; savedGCodeFileNames.Add(sliceItem.GCodePathAndFileName); itemCountBeingWorkedOn++; diff --git a/PrintQueue/PrintQueueItem.cs b/PrintQueue/PrintQueueItem.cs index 10931edb4..c00ace4b4 100644 --- a/PrintQueue/PrintQueueItem.cs +++ b/PrintQueue/PrintQueueItem.cs @@ -279,6 +279,7 @@ namespace MatterHackers.MatterControl.PrintQueue public override void OnClosed(EventArgs e) { + PrintItemWrapper.SlicingOutputMessage -= PrintItem_SlicingOutputMessage; if (unregisterEvents != null) { unregisterEvents(this, null);