I have an application written to monitor some direcotories for XML files and create a fax from them.
I decided to create threading in this application because there are multiple directories and lots of files in each directory.
I have a FaxTemplate that stores the info on which directory to process. Inside of this class I have a timer (because they want it to pause for a while between directory sweeps). I have a class which processes these directories. It has a ProcessDirectory method.
Here is the code in the FaxTemplate class:
Here is the code in the ProcessDirectory class:
Everything runs fine the first time through but it seems that my timer is not getting reset and it is not processing the direcotry more than once. If I take out the threading piece, it will keep processing the directories time after time.
Anyone know why this is happening?
Thanks
I decided to create threading in this application because there are multiple directories and lots of files in each directory.
I have a FaxTemplate that stores the info on which directory to process. Inside of this class I have a timer (because they want it to pause for a while between directory sweeps). I have a class which processes these directories. It has a ProcessDirectory method.
Here is the code in the FaxTemplate class:
Code:
Private RunningThread As Thread
Private Sub mTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles mTimer.Tick
mTimer.Stop()
RaiseEvent Processing(Me)
Console.WriteLine("Timer_Tick: " & Me.TemplateName)
mDirProcessor = New DirProcessor(Me)
RunningThread = New Thread(AddressOf mDirProcessor.ProcessDirectory)
RunningThread.Name = Me.TemplateName
RunningThread.Start()
End Sub
Public Sub StartRead()
mTimer = New System.windows.Forms.Timer
mTimer.Interval = 10000 '300000 '5 minutes
mTimer.Start()
End Sub
Private Sub DirectoryProcessComplete() Handles mDirProcessor.ProcessCompleted
Console.WriteLine("ProcessComplete: " & Me.TemplateName)
RunningThread = Nothing
StartRead()
RaiseEvent ProcessComplete(Me)
End Sub
Here is the code in the ProcessDirectory class:
Code:
Public Sub ProcessDirectory()
Dim File As String
If Not Directory.Exists(mDirectoryName) Then
RaiseEvent ProcessError("Directory " & mDirectoryName & " does not exists.")
Exit Sub
End If
Try
For Each File In Directory.GetFiles(mDirectoryName)
If Right(File, 4).ToUpper = ".XML" Then
ProcessXMLDocument(File)
FileSystem.Kill(File)
End If
Next
Catch ex As Exception
RaiseEvent ProcessError(ex.Message)
End Try
RaiseEvent ProcessCompleted()
End Sub
Everything runs fine the first time through but it seems that my timer is not getting reset and it is not processing the direcotry more than once. If I take out the threading piece, it will keep processing the directories time after time.
Anyone know why this is happening?
Thanks