I am trying change from Delegates to Parallel.ForEach
I see the below works fine.
Imports System.Threading.Tasks
Sub Main()
Dim secs() As Integer = {2, 3, 1}
Parallel.ForEach(secs, AddressOf Method2)
End Sub
Sub Method2(ByVal i As Integer)
Console.WriteLine(i.ToString)
End Sub
But what if my Sub takes more then one variable? Can you show me how I should do the below?
Imports System.Threading.Tasks
Sub Main()
Dim secs() As Integer = {2, 3, 1}
Dim Path as String = "Constant"
Parallel.ForEach(secs, Path, AddressOf Method2)
End Sub
Sub Method2(ByVal i As Integer, path as string )
Console.WriteLine(i.ToString, path)
End Sub
Thank you
You can do this via a Lambda Expression:
This will allow the compiler to create a closure that gets the value of Path, and pass it directly into your method.