I have the below Exception Extension for my in house Winform App. My problem is that I get a generic GDI+
error on ss.save("C:\\HelpMe.jpg", ImageFormat.Jpeg);
It is not every time as it will work and then error out. Sometimes it will work a couple of times in a row.
Is this a "locking" issue, possibly? What else should I look at and/or am doing wrong.
I call this like so -->
catch (Exception ex)
{
ex.LogError(HUD.ShellForm);
}
public static void LogError(this Exception exception, DevExpress.XtraEditors.XtraForm whichForm)
{
GetDesktopImage(whichForm);
SendExceptionMail(exception);
ExceptionMessageBox box = new ExceptionMessageBox(exception);
box.Show(whichForm);
}
private static void SendExceptionMail(Exception exception)
{
SmtpClient smtpClient = new SmtpClient("MailServer");
MailMessage message = new MailMessage
{
From = new MailAddress("MATRIX@anEmail"),
Subject = "MATRIX Application Error",
Body = exception.Message
};
Attachment attachment = new Attachment(@"C:\\HelpMe.jpg");
message.Attachments.Add(attachment);
message.To.Add("Developer@anEmail");
message.To.Add("HelpDesk@anEmail");
smtpClient.Send(message);
}
///<summary>
/// Grabs a screen shot of the App and saves it to the C drive in jpg
///</summary>
private static void GetDesktopImage(DevExpress.XtraEditors.XtraForm whichForm)
{
Rectangle bounds = whichForm.Bounds;
using (Bitmap ss = new Bitmap(bounds.Width, bounds.Height))
using (Graphics g = Graphics.FromImage(ss))
{
g.CopyFromScreen(whichForm.Location, Point.Empty, bounds.Size);
ss.Save("C:\\HelpMe.jpg", ImageFormat.Jpeg);
}
}