Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim k As New jobs
k.AddJob("writedata", AddressOf writedata)
k.AddJob("p", AddressOf p)
k.ApplyJobs()
End Sub
Private Function p() As Boolean
MessageBox.Show("p")
Return True
End Function
Private Function writedata() As Boolean
MessageBox.Show("h")
Return True
End Function
End Class
Public Class jobs
Public Property Jobs As New List(Of job)
Public Sub ApplyJobs()
For Each l In Jobs
If Not l.Invoked Then
l.func().Invoke()
l.Invoked = True
End If
Next
End Sub
Public Sub ApplyJob(name As String)
For Each l In From l1 In From l1 In Jobs Where l1.name = name Where Not l1.Invoked
l.func().Invoke()
l.Invoked = True
Next
End Sub
Public Sub ApplyJobs(ParamArray jobnames() As String)
For Each l In jobnames
ApplyJob(l)
Next
End Sub
Public Sub AddJob(name As String, job As Func(Of Boolean))
Jobs.Add(New job() With {.name = name, .func = job, .Invoked = False})
End Sub
Public Sub AddJob(name As String)
AddJob(name, AddressOf DefaultJobHandler)
End Sub
Public Sub RemovedJob(name As String)
For Each job In Jobs
If job.name = name Then
Jobs.Remove(job)
End If
Next
End Sub
Public Sub RemoveJobs()
Jobs.Clear()
End Sub
Public Sub CopyJob(job1 As String, job2 As String)
For Each job In Jobs
If job.name = job1 Then
AddJob(job2, job.func)
End If
Next
End Sub
Public Sub CopyJob(job As String)
For Each j In Jobs
If j.name = job Then
AddJob(job & "copied", j.func)
End If
Next
End Sub
Private Function DefaultJobHandler() As Boolean
Return True
End Function
End Class
Public Class job
Public Property name As String
Public Property [func] As Func(Of Boolean)
Public Property Invoked As Boolean
End Class