05-18-2015 10:12 AM
Thank you. I will try the array solution.
01-24-2017 10:27 AM
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));
}
01-24-2017 10:37 AM
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 });
01-24-2017 10:43 AM
Thank you very much!
That did it!
01-24-2017 12:34 PM
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!
01-24-2017 12:51 PM
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>.