I've written some code that monitors a fileystem for changes (creation of new files). Every time a file is created in the monitorred filesystem, it's automaticly beeïng moved to another location (C:\Dirty).
The first time the TRIGGER function is triggered, everyting goes fine, but when the trigger fires a second time I get the following error:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The proces has no access to teh file C:\dirty\270704-40be8c06.new because it is beeing used by another process.
The code can't execute the File.Move.
To set up the monitoring I used the:
Public WatchFolder As New FileSystemWatcher
WatchFolder.EnableRaisingEvents = True
When I only MONITOR the filesystem (say a messagebox to display only the System.IO.FileSystemEventArgs.Fullpath) it works fine.
The code has problems when I put an ACTION into it (say moving a file, opening it for reading, etc...).
Here is the code that gives me the error:
Private Sub Trigger(ByVal source As Object, ByVal objSystemIO As System.IO.FileSystemEventArgs)
Dim strdestination As String
Dim btecounter As Byte
If objSystemIO.ChangeType = WatcherChangeTypes.Created Then
strfilename = objSystemIO.FullPath
btecounter = InStrRev(strFileName, "\")
strdestination = Mid(strFileName, btecounter)
File.Move(strFileName, "C:\dirty" & strdestination )
Any help ?