Passing values with parallel extensions and VB.net
I am looking for an example on how to do the following in VB.net with parallel extensions.
Dim T As Thread = New Thread(AddressOf functiontodowork)
T1.Start(InputValueforWork)
Where I am stuck is about how to pass my InputValueforWork parameter to the task
Dim T As Tasks.Task = Tasks.Task.Create(AddressOf functiontodowork)
Any suggestions and possibly a coding example are appreciated.
Andrew
+1
source to share
3 answers
The real problem here is that VB 9 doesn't supportAction<T>
, only Funcs
You can get around this limitation by having a helper in C # like:
public class VBHelpers {
public static Action<T> FuncToAction<T>(Func<T, object> f) {
return p => f(p);
}
}
Then you use it from VB like this:
Public Sub DoSomething()
Dim T As Task = Task.Create(VBHelpers.FuncToAction(Function(p) FunctionToDoWork(p)))
End Sub
Public Function FunctionToDoWork(ByVal e As Object) As Integer
' this does the real work
End Function
0
source to share