In my application I scan images and creat a treeview and when I click on the name of file I show the image in imageViewer,
but when I use delete directory after that I clear the treeview and the imageviewer
treevImage.Nodes.Clear();
imageViewer.Image.Dispose();
imageViewer.Image = null;
Directory.Delete(localPath, true);
I got an exception that one image was used by another thread, the problem is that it is random, the first one or any other image!
The process cannot access the file ‘image9.tif’ because it is being used by another process.
Is there a way to know which part of my application uses that image?
Edit :
When I add
imageViewer.Dispose();
l’app delete the files without exception but when I scan again I got exception when show a new image in imageViewer
Object reference not set to an instance of an object.
Edit 2:
Exception do to dispose() was corrected by MikeNakis but now After I delete the directory I make a new scan and to show the new images in the imageViewer, after dispose() and new ; I can’t see the new images for the new scan
Once you have disposed the imageViewer with
imageViewer.Dispose();you need to then re-create it withimageViewer = new ImageViewer();.