jason907238
2007-08-27, 02:24 PM
I created a file watcher. It works great as long as I don't try to do anything else in AutoCAD. It gives me FATAL ERROR: Unhandled Access Violation Reading 0x000 Exception @ 6e9c038h.
Here is what I did.
In my Class, I started it with
<CommandMethod("Watch")> _
Public Sub Watch()
Try
WriteLine("Starting Watcher")
StartFileWatcher()
Catch ex As Exception
End Try
End Sub
In My Module, I put...
Const DirectoryName As String = "c:\temp"
Public myWatcher As FileSystemWatcher
Public Sub StartFileWatcher()
' Create the FileSystemWatcher
myWatcher = New FileSystemWatcher(DirectoryName)
Try
' Add delegates for the desired events
AddHandler myWatcher.Created, New FileSystemEventHandler( _
AddressOf myWatcher_Created)
AddHandler myWatcher.Changed, New FileSystemEventHandler( _
AddressOf myWatcher_Changed)
AddHandler myWatcher.Renamed, New RenamedEventHandler( _
AddressOf myWatcher_Renamed)
AddHandler myWatcher.Deleted, New FileSystemEventHandler( _
AddressOf myWatcher_Deleted)
' You must set EnableRaisingEvents to true in order for events to be received
myWatcher.EnableRaisingEvents = True
' Display instructions and wait for user to exit program
WriteLine("Make changes to the {0} directory" & DirectoryName)
WriteLine("You will see events generated from those changes.")
WriteLine("Enter WatchOff to exit the program.")
Finally
End Try
End Sub
Public Sub EndFileWatcher()
Try
myWatcher.Dispose()
Catch
End Try
End Sub
' Event handlers respond to events raised by FileSystemEventHandler
Private Sub myWatcher_Changed(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("ChangedFile")
End Sub
Private Sub myWatcher_Created(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("Created File")
End Sub
Private Sub myWatcher_Renamed(ByVal sender As Object, _
ByVal e As RenamedEventArgs)
WriteLine("Renamed File")
End Sub
Private Sub myWatcher_Deleted(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("Deleted File")
End Sub
Public Sub WriteLine(ByVal Text As String)
'Try
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine)
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Text)
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
'Catch
'End Try
End Sub
When I catch the error in WriteLine, it does nothing at all after I have started the watch.
TIA,
Jason
Here is what I did.
In my Class, I started it with
<CommandMethod("Watch")> _
Public Sub Watch()
Try
WriteLine("Starting Watcher")
StartFileWatcher()
Catch ex As Exception
End Try
End Sub
In My Module, I put...
Const DirectoryName As String = "c:\temp"
Public myWatcher As FileSystemWatcher
Public Sub StartFileWatcher()
' Create the FileSystemWatcher
myWatcher = New FileSystemWatcher(DirectoryName)
Try
' Add delegates for the desired events
AddHandler myWatcher.Created, New FileSystemEventHandler( _
AddressOf myWatcher_Created)
AddHandler myWatcher.Changed, New FileSystemEventHandler( _
AddressOf myWatcher_Changed)
AddHandler myWatcher.Renamed, New RenamedEventHandler( _
AddressOf myWatcher_Renamed)
AddHandler myWatcher.Deleted, New FileSystemEventHandler( _
AddressOf myWatcher_Deleted)
' You must set EnableRaisingEvents to true in order for events to be received
myWatcher.EnableRaisingEvents = True
' Display instructions and wait for user to exit program
WriteLine("Make changes to the {0} directory" & DirectoryName)
WriteLine("You will see events generated from those changes.")
WriteLine("Enter WatchOff to exit the program.")
Finally
End Try
End Sub
Public Sub EndFileWatcher()
Try
myWatcher.Dispose()
Catch
End Try
End Sub
' Event handlers respond to events raised by FileSystemEventHandler
Private Sub myWatcher_Changed(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("ChangedFile")
End Sub
Private Sub myWatcher_Created(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("Created File")
End Sub
Private Sub myWatcher_Renamed(ByVal sender As Object, _
ByVal e As RenamedEventArgs)
WriteLine("Renamed File")
End Sub
Private Sub myWatcher_Deleted(ByVal sender As Object, _
ByVal e As FileSystemEventArgs)
WriteLine("Deleted File")
End Sub
Public Sub WriteLine(ByVal Text As String)
'Try
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine)
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Text)
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
'Catch
'End Try
End Sub
When I catch the error in WriteLine, it does nothing at all after I have started the watch.
TIA,
Jason