0
我已經編寫了一個可以使用MS Excel interop動態生成餅圖的類。我節省在Windows Temp文件夾這個餅圖,我試圖刪除包含此餅圖在成功加載在圖像控制權後,該文件夾,迄今:加載後刪除文件
private void Tracker() {
Pbar pbar = new Pbar();
Thread t = new Thread(delegate() {
Draw();
Dispatcher.Invoke(delegate()
{
ImageSource IS = new BitmapImage(new Uri(System.IO.Path.GetTempPath() + "PieChartTemp\\Temp_files\\image002.png", UriKind.Absolute)); ImageBox.Source = IS;
});
});
Thread Track = new Thread(delegate() {
t.Start();
Dispatcher.Invoke(() => pbar.Show());
while (true) {
if (!t.IsAlive) { Dispatcher.Invoke(() => pbar.Close());
System.IO.Directory.Delete(System.IO.Path.GetTempPath() + "PieChartTemp", true);
break;
}
Thread.Sleep(25);
}
});
Track.Start();
}
這種方法的原因一個錯誤,它說該文件正在被一個進程使用(當然是將它加載到圖像控件中的進程),我的問題是如何釋放這個文件以準備刪除它?