• c# 将一个长耗时任务改成task


    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);

  • 相关阅读:
    CentOS7.5 搭建MyCat1.6.6
    idea快速搭建springboot项目
    MySQL存储过程中变量及循环的使用
    windows 安装 jdk1.8并配置环境变量
    CentOS7.5安装JDK1.8
    CentOS7.2安装MySql5.7并开启远程连接授权
    PHP高级工程师面试
    每日英语
    静态化
    php分页实例及其原理
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/10064901.html
Copyright © 2020-2023  润新知