C
Chris Dunaway
Consider the following simple classes/interfaces defined below. When the
derived class raises the events, on which thread is the event code run? Do
I need to do anything to catch the events in my main app? What threading
issues do I have if several of these fileproc classes are instantiated and
run at the same time?
'*** BEGIN CODE
Public Interface IFileProc
ReadOnly Property FileMask() As String
Function Process(ByVal filename As String) As Integer
Event BeginFileProc(ByVal filename As String)
Event EndFileProc(ByVal filename As String)
Event ProcProgress(ByVal filename As String, ByVal percent As Integer)
End Interface
Public MustInherit Class ThreadWrapperBase
Public ReadOnly WorkThread As System.Threading.Thread
Public Sub New()
Me.WorkThread = New System.Threading.Thread(AddressOf Me.StartTask)
End Sub
Public Overridable Sub Start()
Me.WorkThread.Start()
End Sub
Public Overridable Sub [Stop]()
Me.WorkThread.Abort()
End Sub
Private _IsCompleted As Boolean
Public ReadOnly Property IsCompleted() As Boolean
Get
Return _IsCompleted
End Get
End Property
Private Sub StartTask()
_IsCompleted = False
DoTask()
_IsCompleted = True
End Sub
Protected MustOverride Sub DoTask()
End Class
Public Class FileProcClass()
Inherits ThreadWrapperBase
Implement IFileProc
Private _FileToProcess As String
'This is the sub where the file processing actually takes place
Protected Overrides Sub DoTask()
RaiseEvent BeginFileProc(_FileToProcess)
'Process file here
RaiseEvent EndFileProc(_FileToProcess)
End Sub
Public Function Process(...) As Integer Implements IFileProc.Process
_FileToProcess = filename
Start()
End Function
End Class
'*** END CODE
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
derived class raises the events, on which thread is the event code run? Do
I need to do anything to catch the events in my main app? What threading
issues do I have if several of these fileproc classes are instantiated and
run at the same time?
'*** BEGIN CODE
Public Interface IFileProc
ReadOnly Property FileMask() As String
Function Process(ByVal filename As String) As Integer
Event BeginFileProc(ByVal filename As String)
Event EndFileProc(ByVal filename As String)
Event ProcProgress(ByVal filename As String, ByVal percent As Integer)
End Interface
Public MustInherit Class ThreadWrapperBase
Public ReadOnly WorkThread As System.Threading.Thread
Public Sub New()
Me.WorkThread = New System.Threading.Thread(AddressOf Me.StartTask)
End Sub
Public Overridable Sub Start()
Me.WorkThread.Start()
End Sub
Public Overridable Sub [Stop]()
Me.WorkThread.Abort()
End Sub
Private _IsCompleted As Boolean
Public ReadOnly Property IsCompleted() As Boolean
Get
Return _IsCompleted
End Get
End Property
Private Sub StartTask()
_IsCompleted = False
DoTask()
_IsCompleted = True
End Sub
Protected MustOverride Sub DoTask()
End Class
Public Class FileProcClass()
Inherits ThreadWrapperBase
Implement IFileProc
Private _FileToProcess As String
'This is the sub where the file processing actually takes place
Protected Overrides Sub DoTask()
RaiseEvent BeginFileProc(_FileToProcess)
'Process file here
RaiseEvent EndFileProc(_FileToProcess)
End Sub
Public Function Process(...) As Integer Implements IFileProc.Process
_FileToProcess = filename
Start()
End Function
End Class
'*** END CODE
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.