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); } } }