进程无法访问文件 [英] process cannot access file
问题描述
您好
我想删除以前使用BitmapImage访问的图像文件.
像这样:
hello
I want do delete an image-file i accessed before with a BitmapImage.
Like this:
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"c:\test.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();
System.IO.File.Delete(@"c:\test.jpg");
File.Delete引发以下异常:
"System.IO.IOException:进程无法访问文件"C:\ test.txt".因为它正在被另一个进程使用."
我如何告诉WPF释放文件以便可以将其删除?
wpfnoob
File.Delete throws the following exception:
"System.IO.IOException: The process cannot access the file "C:\test.txt" because it is being used by another process."
How can i tell WPF to free the file so i can delete it?
wpfnoob
推荐答案
您好wpfnoob,
看看chache选项...
Hi wpfnoob,
have a look at the chache option...
BitmapImage bi = 新
BitmapImage bi = new BitmapImage();
bi.BeginInit();
//bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bi.CacheOption =
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = Uri ( UriKind .RelativeOrAbsolute);
bi.UriSource = new Uri(@"c:\test.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();
System.IO. File .Delete( @"c:\ test.jpg"");
System.IO.File.Delete(@"c:\test.jpg");
这篇关于进程无法访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!