views:

103

answers:

1

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

+1  A: 

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)
Chris Haas
How would I invoke that with the parallel extensions? I know that this works for threading normal tasks but the parallel extensions are a bit different and have a different syntax. Also I'd like to have it call a function instead of an entire class.
Middletone
I modified the code above. The same basic threading principals should work for parallel. Instead of using the Generic Action(Of T1, T2) just use the non-Generic Action() which works on regular Objects. I know its not as ideal as a Generic call but it works just the same.
Chris Haas
I'm accepting this as the solution even though it's not ideal for what I would like to do. It works however and sometimes that all that matters.
Middletone