4

次のコードがあります。

Bitmap image = new Bitmap(filePath);
...
image.Save(someOtherPath);
image.Dispose();
File.Delete(filePath);
File.Move(someOtherPath, filePath);

File.Delete 行で次のエラーが発生します。

The process cannot access the file '...' because it is being used by another process.

C# でファイルのロックを解除するにはどうすればよいですか?

4

2 に答える 2

3

試す

using(var image = new Bitmap(filepath))
{
    image.Save(someOtherPath);
}


File.Delete(filePath);
File.Move(someOtherPath, filePath);
于 2012-08-29T08:47:49.900 に答える
0
the mistake came from the file open by your Image class
Image image;

using(FileStream myStream = new FileStream(path))
  {    
     image = Image.FromStream(myStream);
  }
于 2012-08-29T08:55:38.240 に答える