Pim*_*ger 0 .net vb.net file-io locking
好吧,我是VB.NET和桌面应用程序开发的新手.简化这是我的应用程序中发生的事情:
Dim Files() As New List(Of IO.FileInfo)
Files.Add( (New IO.FileInfo("C:\img1.jpg")) )
Files.Add( (New IO.FileInfo("C:\img2.jpg")) )
'Picture is a Windows.Forms.PictureBox in my WinForm '
Picture.Image = New System.Drawing.Bitmap(Files(0).FullName)
Picture.image = Nothing
CurrentFile = Files(0)
'Show next pic (img2)'
Files.RemoveAt(0)
Picture.Image = New System.Drawing.Bitmap(Files(0).FullName)
'Move img1 to other location '
CurrentFile.MoveTo("C:\other\img1.jpg")
Run Code Online (Sandbox Code Playgroud)
最后一行将抛出一个异常,说img1因为正在使用而无法移动.所以我的应用程序仍在使用它,但如何让我的应用程序停止锁定文件?没有什么可以保持它(据我所见)