'Klasse kapselt einen Prozess zur Ausführung in einem seperaten Thread
Protected Class SingleTaskProcessor
Inherits ThreadWrapperBase
Private Delegate Sub DoTaskDelegate(ByVal Obj As T)
Private Delegate Sub WorkCompletedDelegate(ByVal Sender As _
SingleTaskProcessor, ByVal Obj As T)
Private Delegate Sub StartTaskDelegate(ByVal Sender As _
SingleTaskProcessor, ByVal Obj As T, ByRef Cancel As Boolean)
Private Delegate Sub AbbortTaskDelegate(ByVal Sender As _
SingleTaskProcessor, ByVal Obj As T)
'das zu bearbeitende Objekt
Private mObj As T
Private mParent As MultiTaskProcessor(Of T)
Public Sub New(ByVal Parent As MultiTaskProcessor(Of T), ByVal Obj _
As T, ByVal ThreadName As String)
MyBase.New(ThreadName)
mParent = Parent
mObj = Obj
End Sub
Public Sub New(ByVal Parent As MultiTaskProcessor(Of T), ByVal Obj _
As T, ByVal IsBackground As Boolean)
MyBase.New(IsBackground)
mParent = Parent
mObj = Obj
End Sub
Public Sub New(ByVal Parent As MultiTaskProcessor(Of T), ByVal Obj _
As T, ByVal IsBackground As Boolean, ByVal ThreadName As String)
MyBase.New(IsBackground, ThreadName)
mParent = Parent
mObj = Obj
End Sub
Public Sub New(ByVal Parent As MultiTaskProcessor(Of T))
MyBase.New()
mParent = Parent
End Sub
Public Sub New(ByVal Parent As MultiTaskProcessor(Of T), ByVal Obj _
As T)
MyBase.New()
mParent = Parent
mObj = Obj
End Sub
Protected Overrides Sub DoTask()
If mDebugMode Then Debug.WriteLine(mThreadName & "::" & "Begin" & _
"DoTask")
If mParent Is Nothing Then Exit Sub
Dim Del As New DoTaskDelegate(AddressOf mParent.DoWork)
Del.Invoke(mObj)
End Sub
Protected Overrides Sub WorkCompleted()
If mDebugMode Then Debug.WriteLine(mThreadName & "::" & "Work" & _
"Complete!")
If mParent Is Nothing Then Exit Sub
Dim Del As New WorkCompletedDelegate(AddressOf _
mParent.m_SingleTaskCompleted)
Del.Invoke(Me, mObj)
End Sub
Protected Overrides Sub TaskAbborted()
If mDebugMode Then Debug.WriteLine(mThreadName & "::" & _
"Abborted")
If mParent Is Nothing Then Exit Sub
Dim Del As New AbbortTaskDelegate(AddressOf _
mParent.m_SingleTaskAbborted)
Del.Invoke(Me, mObj)
End Sub
Protected Overloads Overrides Sub TaskStart(ByRef Cancel As Boolean)
If mDebugMode Then Debug.WriteLine(mThreadName & "::" & _
"Started")
If mParent Is Nothing Then
Cancel = True
Exit Sub
End If
Dim Del As New StartTaskDelegate(AddressOf _
mParent.m_SingleTaskStart)
Del.Invoke(Me, mObj, Cancel)
End Sub
Protected Overrides Sub TaskAbbortRequest(ByRef Cancel As Boolean)
If mDebugMode Then Debug.WriteLine(mThreadName & "::" & "Abbort" & _
"Requested")
End Sub
End Class
'Klasse für die Events
Public Class MTP_ThreadEventArgs
Inherits EventArgs
Public Tag As Object
Public Obj As T
Public Cancel As Boolean = False
Public Sub New(ByVal Obj As T, ByVal Tag As Object, ByVal Cancel As _
Boolean)
Me.Tag = Tag
Me.Obj = Obj
Me.Cancel = Cancel
End Sub
End Class |