无法删除另一个进程正在使用的文件

时间:2012-11-29 23:46:57

标签: c# image process screenshot delete-file

我正在尝试在制作屏幕截图后删除文件。代码如下:

private static void makeSc()
    {
        DateTime d = DateTime.Now;
        string currentDT = String.Format("{0:yyyy-MM-dd-hhmmsstt}", d);
        string scrFilename = currentDT+".jpg";
        int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
        int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
        Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
        Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
        gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
        bmpScreenShot.Save(scrFilename, ImageFormat.Jpeg);

        //delete file
        bmpScreenShot.Dispose();
        Thread.Sleep(20);
        File.Delete(scrFilename);

    }

似乎也没有Dispose()延迟。有什么想法吗?

0 个答案:

没有答案