joblist and example


SUBMITTED BY: Guest

DATE: Jan. 2, 2014, 12:41 p.m.

FORMAT: Text only

SIZE: 2.9 kB

HITS: 1562

  1. Public Class Form1
  2. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  3. Dim k As New jobs
  4. k.AddJob("writedata", AddressOf writedata)
  5. k.AddJob("p", AddressOf p)
  6. k.ApplyJobs()
  7. End Sub
  8. Private Function p() As Boolean
  9. MessageBox.Show("p")
  10. Return True
  11. End Function
  12. Private Function writedata() As Boolean
  13. MessageBox.Show("h")
  14. Return True
  15. End Function
  16. End Class
  17. Public Class jobs
  18. Public Property Jobs As New List(Of job)
  19. Public Sub ApplyJobs()
  20. For Each l In Jobs
  21. If Not l.Invoked Then
  22. l.func().Invoke()
  23. l.Invoked = True
  24. End If
  25. Next
  26. End Sub
  27. Public Sub ApplyJob(name As String)
  28. For Each l In From l1 In From l1 In Jobs Where l1.name = name Where Not l1.Invoked
  29. l.func().Invoke()
  30. l.Invoked = True
  31. Next
  32. End Sub
  33. Public Sub ApplyJobs(ParamArray jobnames() As String)
  34. For Each l In jobnames
  35. ApplyJob(l)
  36. Next
  37. End Sub
  38. Public Sub AddJob(name As String, job As Func(Of Boolean))
  39. Jobs.Add(New job() With {.name = name, .func = job, .Invoked = False})
  40. End Sub
  41. Public Sub AddJob(name As String)
  42. AddJob(name, AddressOf DefaultJobHandler)
  43. End Sub
  44. Public Sub RemovedJob(name As String)
  45. For Each job In Jobs
  46. If job.name = name Then
  47. Jobs.Remove(job)
  48. End If
  49. Next
  50. End Sub
  51. Public Sub RemoveJobs()
  52. Jobs.Clear()
  53. End Sub
  54. Public Sub CopyJob(job1 As String, job2 As String)
  55. For Each job In Jobs
  56. If job.name = job1 Then
  57. AddJob(job2, job.func)
  58. End If
  59. Next
  60. End Sub
  61. Public Sub CopyJob(job As String)
  62. For Each j In Jobs
  63. If j.name = job Then
  64. AddJob(job & "copied", j.func)
  65. End If
  66. Next
  67. End Sub
  68. Private Function DefaultJobHandler() As Boolean
  69. Return True
  70. End Function
  71. End Class
  72. Public Class job
  73. Public Property name As String
  74. Public Property [func] As Func(Of Boolean)
  75. Public Property Invoked As Boolean
  76. End Class

comments powered by Disqus