我的内部 Winform 应用程序有以下异常扩展。我的问题是我得到一个generic GDI+
错误ss.save("C:\\HelpMe.jpg", ImageFormat.Jpeg);
它不是每次都有效,然后出错。有时它会连续工作几次。
这可能是一个“锁定”问题吗?我还应该看什么和/或做错了什么。
我这样称呼它-->
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);
}
}