Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get Graph.DataSource to work in WPF i (threading issue?)

Solved!
Go to solution

Thank you.  I will try the array solution.

 

0 Kudos
Message 11 of 16
(2,649 Views)

Hi Phansen,

I'm having an issue and would appreciate your help.

For some reason one dimensional array works but 2D does not.  I get "Parameter count mismatch." exception.

Do you see the issue here?  Thank you!

 

        private void GetData(Action<object> actionPlotData)
        {
            //double[] testData = new double[] { 1, 2, 3, 4 }; // This works
            double[][] testData = new double[2][]; // This does not
            testData[0] = new double[] { 1, 2, 3, 4 };
            testData[1] = new double[] { 2, 4, 6, 8 };
Dispatcher.BeginInvoke(actionPlotData, testData); } private async void ButtonAcquirePackets_Click(object sender, RoutedEventArgs e) { await Task.Run(() => GetData(data => GraphNode0.DataSource = data)); }
0 Kudos
Message 12 of 16
(974 Views)
Solution
Accepted by topic author kirko7

I believe the issue is BeginInvoke expects a params object[] for the arguments to the delegate. A double[] can't be implicitly converted to object[] (because it would require boxing every double), but double[][] can be (because a double[] array is directly compatible with object). So BeginInvoke thinks you are trying to call an Action<object> method with two parameters, testData[0] and testData[1], instead of a single parameter, testData.

 

To fix this, you just need to be explicit about the params object[] argument:

 

    Dispatcher.BeginInvoke(actionPlotData, new object[] { testData });

~ Paul H
Message 13 of 16
(971 Views)

Thank you very much!

That did it!

0 Kudos
Message 14 of 16
(968 Views)

This gotta be my last question because this thread pretty much covers everything.  But here's the last one from me...

I have a list of Graphs because I have 8 sets of data from different nodes.  But I acquire this data at the same time from the same DAS.  So I need to update 8 Graphs at the same time and I have them in the List in order to loop through them.

Graphs = new List<Graph>();
Graphs.Add(GraphNode0);
Graphs.Add(GraphNode1);
Graphs.Add(GraphNode2);
Graphs.Add(GraphNode3);
Graphs.Add(GraphNode4);
Graphs.Add(GraphNode5);
Graphs.Add(GraphNode6);
Graphs.Add(GraphNode7);

Is it possible to modify this call to accept List of Graphs?

private async void ButtonAcquirePackets_Click()
{
     await Task.Run(() => GetData(data => GraphNode0.DataSource = data));
}
private void GetData(Action<object> actionPlotData)
{
     // Get my data here...
double[][] testData = Scan();

// Loop here and somehow index into List of Graphs...? Dispatcher.BeginInvoke(actionPlotData, new object[] { testData }); }

I'm actually curious if this is even a good design.  Thank you in advance!

0 Kudos
Message 15 of 16
(962 Views)

I don't think there's anything wrong with dispatching a single method to update all the relevant graphs. As shown in previous exmples in this thread (here and here), the delegate passed to BeginInvoke can have any type, so Action<Graph[], object[]>, or Action<IList<Graph>, double[][]>, or etc., would work just as well as Action<object>.

~ Paul H
Message 16 of 16
(960 Views)