开发者

How can I get parallel extensions to run a function that has two input parameters?

I've tried really hard to get this to work and have had no luck. How can I get parallel extensions开发者_运维百科 to run a function that has two input parameters? I'm using the more recent version, the Reactive Extensions with the 3.5 framework.

I need to get the extensions to run act (or the function ProcessOrder) but no matter what I try I can't get it to do it.

Dim act As New System.Action(Of Int32, Date)(AddressOf ProcessOrder)
act(CInt(RowA("ID")), RunDate)
Tasks.Task.Factory.StartNew(act)

I used to be able to do the following:

Dim A(0) As Object
A(0) = CInt(RowA("ID"))
A(1) = RunDate
Tasks.Task.Create(AddressOf ProcessOrder, A)

But it's not supported anymore


Create a small class that has the two parameters as properties and have a method on the class that acts upon those properties.

Public Class ProcessClass
    Private _p1 As Integer
    Private _p2 As Date
    Public Sub New(ByVal p1 As Integer, ByVal p2 As Date)
        Me._p1 = p1
        Me._p2 = p2
    End Sub
    Public Sub ProcessOrder()
        Trace.WriteLine(String.Format("{0}:{1}", _p1, _p2))
    End Sub
End Class

And then invoke it by:

    Dim Obj As New ProcessClass(1, DateTime.Now())
    Dim Act As New System.Action(AddressOf Obj.ProcessOrder)
    System.Threading.Tasks.Task.Factory.StartNew(Act)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜