From 990c103b39b43a654eeb1da5385c20552f57ba92 Mon Sep 17 00:00:00 2001 From: tomse <1444539+tomse@users.noreply.github.com> Date: Sun, 1 Feb 2026 14:34:25 +0100 Subject: [PATCH] fix output image not being loaded --- PDFWorkflowManager/PDFWorkflowManager/MainForm.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/PDFWorkflowManager/PDFWorkflowManager/MainForm.cs b/PDFWorkflowManager/PDFWorkflowManager/MainForm.cs index f34b296..4b1726b 100644 --- a/PDFWorkflowManager/PDFWorkflowManager/MainForm.cs +++ b/PDFWorkflowManager/PDFWorkflowManager/MainForm.cs @@ -383,7 +383,7 @@ namespace PDFWorkflowManager } catch (Exception ex) { - MessageBox.Show("Could not load preview image from Work directory." + ex, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Could not load preview image from Work directory." + ex.Message, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkOutDir))) @@ -393,23 +393,18 @@ namespace PDFWorkflowManager string[] strOutFiles = Directory.GetFiles(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkOutDir), "*.tif"); if (strOutFiles.Length > 0) { - string tempCopyPath = Path.Combine(tempDir, "preview_out.tif"); - File.Copy(strOutFiles[0], tempCopyPath, true); - - using (var memoryStream = new MemoryStream(File.ReadAllBytes(tempCopyPath))) + using (var memoryStream = new MemoryStream(File.ReadAllBytes(strOutFiles[0]))) using (var bitmap = new Bitmap(memoryStream)) { + // Create a copy of the bitmap to ensure the file is released pictureBox2.Image = new Bitmap(bitmap); } - // Release file handle so tempCopyPath is writeable - GC.Collect(); - GC.WaitForPendingFinalizers(); - File.Delete(tempCopyPath); + // At this point, the file is fully released } } catch (Exception ex) { - MessageBox.Show("Could not load preview image from Work\\out directory." + ex, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Could not load preview image from Work\\out directory. " + ex.Message, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }