c# - Disposing Temp Files and Deleting them -
i'm using winforms
. made simple image viewer application using picturebox
display images. made way create temporary files. these files picture files. when application done using image want able delete these temporary on formclosing
files located at: c:\users\taji01\appdata\local\temp\8bd93a0dec76473bb82a12488fd350af
cannot call file.delete(c://picture.jpg) because application still using them though there picture displaying in application. tried dispose couldn't figure how how that. should using using statement? there better way dispose , delete file or there way make work?
_filename = path.combine(path.gettemppath(), guid.newguid().tostring("n")); file.copy(imagepath, _filename); _stream = new filestream(_filename, filemode.open, fileaccess.read, fileoptions.deleteonclose); this._source = image.fromstream(_stream);
error: "the process cannot access file c:\picture.jpg because being used process" exeption thrown: 'system.io.io.exception' in msconrlib.dll (the process cannot access file 'c:\picture.jpg' because being used procesas")
you need close()
filestream
.
Comments
Post a Comment