Hi,
I am having one of those moments where I am struggling to do something neatly which automatically makes me think maybe I have got this wrong.
I have a ServiceTaskManager (yes, I know people will not like the name) class:
Public Class ServiceTaskManager
Inherits MyAbstractClass
Implements IWork, IServiceWork
Public Sub ManageTasks(ByVal args() As String) Implements IWork.ManageTasks
Dim task As New SomeTask()
While IsRunning
StartIdleTask(task)
Thread.Sleep(ManagerThreadSleepTime)
End While
End Sub
End Class
The StartIdleTask method looks something like:
Public Sub StartIdleTask(ByVal task As ServiceTask)
If task.Status = ThreadStatusType.Idle Then
task.Status = ThreadStatusType.Busy
AddHandler task.TearingDown, AddressOf ConcludeTask
ThreadPool.QueueUserWorkItem(AddressOf task.Start)
End If
End Sub
Each SomeTask looks something like:
Public Class SomeTask
Inherits MyAbstractTask
Public Overrides Sub Start(ByVal state As Object)
'Work.
TearDown()
End Sub
Public Overrides Sub TearDown()
TearDown(Me)
End Sub
End Class
And the abstract TearDown method:
Protected Sub TearDown(ByVal task As ServiceTask)
RaiseEvent TearingDown(task)
End Sub
As you can see things get pretty awkward because of having to call the TearDown method which raises an event in the MyAbstract class to ultimately mark the task as Idle. Apart from this I am reasonably happy with the way everything works.
Am I missing something obvious in the .NET framework? Have I gone off at a tangent? I am always wanting to learn from the mistakes.
If you need me to post more code then no problem.