} // constructor public void AddNewCurves(CurvePoint[][] xCurvePoints, double xYShift) { if (!Dispatcher.CheckAccess()) { Action lAction = () => { AddNewCurves(xCurvePoints, xYShift); }; App.Current.Dispatcher.BeginInvoke(lAction); return; } // find the Y axis LinearAxis lYAxis = null; foreach (IAxis lAxis in _MainWindow.myChart.Axes) { if (lAxis.Orientation != AxisOrientation.Y) continue; lYAxis = lAxis as LinearAxis; } int lCount = xCurvePoints.GetUpperBound(0); LineSeries[] lLineSeries = new LineSeries[lCount]; for (int x = 0, n = lCount; x < n; x++) { LineSeries lLine = new LineSeries(); lLineSeries[x] = lLine; lLine.DependentRangeAxis = lYAxis; lLine.Title = "manually added curve"; lLine.SetBinding(LineSeries.ItemsSourceProperty, new Binding()); lLine.IndependentValueBinding = new Binding("Time"); lLine.DependentValueBinding = new Binding("CurveId"); Style lLineStyle = new Style(typeof(Polyline)); //lLineStyle.Setters.Add(new Setter(Polyline.StrokeStartLineCapProperty, PenLineCap.Flat)); //lLineStyle.Setters.Add(new Setter(Polyline.StrokeEndLineCapProperty, PenLineCap.Triangle)); Style lPointStyle = new Style(typeof(DataPoint)); if (xYShift == 0.0) { lLineStyle.Setters.Add(new Setter(Polyline.StrokeThicknessProperty, 3.0)); lPointStyle.Setters.Add(new Setter(DataPoint.WidthProperty, 0.0)); lPointStyle.Setters.Add(new Setter(DataPoint.BackgroundProperty, new SolidColorBrush(Colors.LightGreen))); } else { lLineStyle.Setters.Add(new Setter(Polyline.StrokeThicknessProperty, 1.0)); lPointStyle.Setters.Add(new Setter(DataPoint.WidthProperty, 0.0)); lPointStyle.Setters.Add(new Setter(DataPoint.BackgroundProperty, new SolidColorBrush(Colors.Black))); } lLine.PolylineStyle = lLineStyle; lLine.DataPointStyle = lPointStyle; xCurvePoints[x][0].CurveId -= xYShift; xCurvePoints[x][1].CurveId -= xYShift; lLine.ItemsSource = xCurvePoints[x]; _MainWindow.myChart.Series.Add(lLine); } } //
} // private void DoSomething(int xId, long xWakeUpTimeInTicks, CurvePoint[][] xPoints) { // time sensitive stuff first double lFromTicks = Stopwatch.GetTimestamp(); Thread.Sleep(10); double lToTicks = Stopwatch.GetTimestamp(); // time insensitive stuff double lFromMillisecs = (lFromTicks - xWakeUpTimeInTicks) / Stopwatch.Frequency * 1000.0; double lToMillisecs = (lToTicks - xWakeUpTimeInTicks) / Stopwatch.Frequency * 1000.0; CurvePoint lFrom = new CurvePoint(xId, lFromMillisecs); CurvePoint lTo = new CurvePoint(xId, lToMillisecs); xPoints[xId] = new CurvePoint[] { lFrom, lTo }; } //
private void OnMicroTimer(int xSenderThreadId, long xWakeUpTimeInTicks, long xDelayInTicks) { _ViewModel.AddInfoText("OnMicroTimer event raised"); CurvePoint[][] lPoints = new CurvePoint[cNumTasks][]; ParallelLoopResult lResult = Parallel.For(0, cNumTasks, (xInt) => DoSomething(xInt, xWakeUpTimeInTicks, lPoints)); // the first measurement is not precise, so we discard it if (_Once) { _Once = false; return; } double lCallNo = _NumberOfMicroTimerCalls++; lCallNo /= cNumTriggers; _ViewModel.AddNewCurves(lPoints, lCallNo); } //