From 474757af5eb746afa531360cbd4fcb15e84efcad Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Tue, 5 Nov 2019 17:33:02 +0100 Subject: [PATCH] Screenshoter: Avoid exception while copy screen when there is no desktop. --- VAR.ScreenAutomation/Code/Screenshoter.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/VAR.ScreenAutomation/Code/Screenshoter.cs b/VAR.ScreenAutomation/Code/Screenshoter.cs index 24b3b35..127e4ed 100644 --- a/VAR.ScreenAutomation/Code/Screenshoter.cs +++ b/VAR.ScreenAutomation/Code/Screenshoter.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Windows.Forms; namespace VAR.ScreenAutomation.Code @@ -29,11 +30,15 @@ namespace VAR.ScreenAutomation.Code bmp = new Bitmap(width ?? 0, height ?? 0); } - // Draw the screenshot into our bitmap. - using (Graphics g = Graphics.FromImage(bmp)) + try { - g.CopyFromScreen(left ?? 0, top ?? 0, 0, 0, bmp.Size); + // Draw the screenshot into our bitmap. + using (Graphics g = Graphics.FromImage(bmp)) + { + g.CopyFromScreen(left ?? 0, top ?? 0, 0, 0, bmp.Size); + } } + catch (Exception) { /* Nom Nom Nom */} return bmp; } }