From 46498ce3377cd9690fe90e33ae03d84e215b9971 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 25 Jan 2024 19:40:56 +0100 Subject: [PATCH] Printing: Show message box when error in printing process occurs --- Elwig/Helpers/Printing/Pdf.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Elwig/Helpers/Printing/Pdf.cs b/Elwig/Helpers/Printing/Pdf.cs index f7040d4..103405a 100644 --- a/Elwig/Helpers/Printing/Pdf.cs +++ b/Elwig/Helpers/Printing/Pdf.cs @@ -74,12 +74,16 @@ namespace Elwig.Helpers.Printing { } public static async Task Print(string path, int copies = 1) { - var p = new Process() { StartInfo = new() { FileName = PdfToPrinter } }; - p.StartInfo.ArgumentList.Add(path); - p.StartInfo.ArgumentList.Add("/s"); - p.StartInfo.ArgumentList.Add($"copies={copies}"); - p.Start(); - await p.WaitForExitAsync(); + try { + var p = new Process() { StartInfo = new() { FileName = PdfToPrinter } }; + p.StartInfo.ArgumentList.Add(path); + p.StartInfo.ArgumentList.Add("/s"); + p.StartInfo.ArgumentList.Add($"copies={copies}"); + p.Start(); + await p.WaitForExitAsync(); + } catch (Exception e) { + MessageBox.Show("Beim Drucken ist ein Fehler aufgetreten:\n\n" + e.Message, "Fehler beim Drucken"); + } } } }