sj1187534 Posted May 21, 2004 Posted May 21, 2004 (edited) Dim dt As DateTime = DateTime.Now() Dim permlogfilename As String = "Gisb_Log_Out_" & dt.Year & dt.Month & dt.Day & dt.Hour & dt.Minute & dt.Second & ".txt" Dim permlogfilepath As String = Me.logDir & "OUTLOG\" & permlogfilename templogfileinfo.CopyTo(permlogfilepath) templogfileinfo.Delete() When it is attemtping to copy the file at the .CopyTo command, it is saying that the file represented by "permlogfilepath" is being used by another process. Any ideas? SJ Edited May 21, 2004 by sj1187534 Quote
talahaski Posted May 21, 2004 Posted May 21, 2004 It looks like this line permlogwriter.Write(templogfileinfo.OpenRead) opens templogfileinfo and you never close it, you close permlogwriter. try permlogwriter.Write(templogfileinfo.OpenRead) permlogwriter.flush() templogfileinfo.close() permlogwriter.close() Quote
talahaski Posted May 21, 2004 Posted May 21, 2004 looks like you just edited your post and removed all the important code. Quote
sj1187534 Posted May 21, 2004 Author Posted May 21, 2004 Yes...I did. The code that I removed was redundant. Even the code I have right now is giving me the same error. Seems strange to me. That is the only instance of the templogfile I am using. By the way, a fileinfo class does not have a Close() method. SJ looks like you just edited your post and removed all the important code. Quote
talahaski Posted May 25, 2004 Posted May 25, 2004 Sorry, hard to keep track of what classes have close methods and which ones do not. You might want to try this to figure out exactly when the file gets locked. Run in debug mode and step through line by line, between stepping through each line of code, open a window explorer, find the source and dest files, try to rename these files. If the rename works, nothing is holding the file open, rename it back to the original name, and run the next step and repeat. Eventually you will find that the rename give a error, at this point go back to the previous line of code you ran and that is the problem. Quote
inzo21 Posted May 26, 2004 Posted May 26, 2004 Hey sj, Try to implement you're own dispose and finalize methods on the class. Make the class inherit idisposable and then implement a dispose method that closes any stream. Even though there is no close method on a FileInfo object, sometime it still gets stored in the heap until the garbage collector picks it up. It might be as simple as invoking the garbage collector automatically in the dispose method: Public Overloads Sub Dispose() Implements IDisposable.Dispose If DisposeCalled Then Return End If ' call your stream closures here GC.SuppressFinalize(Me) DisposeCalled = True End Sub hope this helps. inzo Quote he who forgets will be destined to remember... (E.Vedder)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.