0

我的内部 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);
        }
    }
4

1 回答 1

1

这通常是因为:

  1. 目标目录不存在
  2. 目标文件名已被使用
  3. 目标文件名实际上是一个目录
  4. 用户无权写入目标文件

... ETC ...

本质上,这通常是由于 GDI 无法创建/写入文件造成的。顺便说一句,在 Vista 中,您没有对 C:\ 的写入权限

于 2009-09-09T22:15:36.030 回答