vb.net - .NET app locks file -
OK, I'm really new to VB.NET and desktop application development. Simplified is what is happening in my application:
Dim files (as of the new list of IO.FileInfo). (Add new IO.FileInfo ("C: \ img1.jpg"))) files. Add ((new IO.fileinfo ("C: \ img2.jpg"))) 'Picture is a Windows. Farm Picture box in my WinForm 'picture. Image = new system. Drawing. Bitmap (files (0) .FullName) Picture.image = nothing CurrentFile = Files (0) 'Show next picture (IMG2)' files Removable (0) pictures. Image = new system. Drawing Bitmap (Files (0) .FullName) Move Img1 to another location 'CurrentFile.MoveTo ("C: \ other \ img1.jpg")
The last line throws an exception saying That img1 can not be moved because it is in use. My application is still using it, but how to stop locking my app?
guilty party is betamap I
. Bitmap (string)
The constructor's result is in the bitmap, until the bitmap is disposed of, locked on the file. See:
The file is locked until the bitmap is dealt.
To fix the problem, either settle the bitmap (if you have finished it), or manually load the byte into a memory stream from the file and from MemoryStream Load the bitmap (again, bitmap (stream)
the constructor requires the stream to be open, so you can not create a filestream on the file, you will have to load the byte in memory , And should keep By the time MemoryStream long as you are not finished with the bitmap.)
Comments
Post a Comment