-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading.vb
More file actions
59 lines (41 loc) · 1.89 KB
/
MultiThreading.vb
File metadata and controls
59 lines (41 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Imports System.Threading.Tasks
Imports System.Threading
Imports System.Windows.Forms
Public Class MultiThreading
Private this As Form
Public Thread As task
Public Sub New(form As Form)
this = form
End Sub
Public Sub Run(ByVal func As Action)
Thread = Task.Factory.StartNew(func)
End Sub
'Public Sub RunWithCancellationToken(fun As Action, CancellationToken As CancellationToken)
' Thread = Task.Factory.StartNew(fun, CancellationToken)
'End Sub
'Public Sub Run(ByVal fun As Action, Completion As Action)
' Thread = Task.Factory.StartNew(fun)
' Dim CheckStatus As Task = Task.Factory.StartNew(Sub()
' While True
' If Not Thread.Status = TaskStatus.Running Then
' ThreadSafe("", Sub(n)
' Completion()
' End Sub)
' Exit While
' End If
' End While
' End Sub)
'End Sub
Public Sub ThreadSafe(ByVal data As Object, ByVal func As Action(Of Object))
If this.InvokeRequired Then
Dim d As New DelegateGetData(AddressOf ThreadSafe)
Try
this.Invoke(d, New Object() {data, func})
Catch ex As Exception
End Try
Else
func(data)
End If
End Sub
Private Delegate Sub DelegateGetData(ByVal data As Object, ByVal func As Action(Of Object))
End Class