public Task<ObservableCollection<WaterFallDataSource2>> InitalrenderSourceandBrush2(int width) { Stopwatch w = new Stopwatch(); w.Start(); points3.Clear(); int wavelength = GlobalStorage.BigWaves.Length; int allRows = wavelength / width; w.Stop(); Debug.WriteLine("w.ElapsedMilliseconds:" + w.ElapsedMilliseconds); Debug.WriteLine("allRows:" + allRows); if (allRows > 0) { Parallel.For(0, _pagesize, (lk) => { ObservableCollection<DataPoint3> dataPoints = new ObservableCollection<DataPoint3>(); for (byte j = 0; j < 150; j++) { for (short i = 0; i < width; i++) { DataPoint3 dataPoint = new DataPoint3() { VariableX = i, VariableY = j }; dataPoint.Type = GetColorIndex2(GlobalStorage.BigWaves[lk * width + i][j]); dataPoints.Add(dataPoint); } } WaterFallDataSource2 waterFallDataSource = new WaterFallDataSource2(); waterFallDataSource.DataPoints = dataPoints; waterFallDataSource.BrushInfo = brushes; waterFallDataSource.Index = lk; waterFallDataSource.Width = width; waterFallDataSource.StartTime = BeatWaveDataConversionExtension.WaveDotToDateTime(BeatInfoCache.BeatInfos.ElementAt(lk * width).R).ToString(); points3.Add(waterFallDataSource); }); return Task.FromResult<ObservableCollection<WaterFallDataSource2>>(points3.OrderBy(p => p.Index).ToObservableCollection<WaterFallDataSource2>()); } else { ObservableCollection<DataPoint3> dataPoints = new ObservableCollection<DataPoint3>(); WaterFallDataSource2 waterFallDataSource = new WaterFallDataSource2(); for (byte j = 0; j < 150; j++) { for (short i = 0; i < wavelength; i++) { short value = GlobalStorage.BigWaves[i][j]; DataPoint3 dataPoint = new DataPoint3() { VariableX = i, VariableY = j }; dataPoint.Type = GetColorIndex2(value); dataPoints.Add(dataPoint); } } waterFallDataSource.DataPoints = dataPoints; waterFallDataSource.BrushInfo = brushes; waterFallDataSource.Index = 0; waterFallDataSource.Width = width; points3.Add(waterFallDataSource); return Task.FromResult<ObservableCollection<WaterFallDataSource2>>(points3); } }
调用
var reuslt = await _stTrendController.InitalrenderSourceandBrush2((int)firstrowgrid.ActualWidth - 27);