zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    数学趣题——汉诺塔
    数学趣题——选美比赛
    数学趣题——计算组合数
    (结构型模式)Proxy——代理模式
    SHELL脚本的基础知识2——使用结构化命令
    数学趣题——寻找假币
    Cocoa使用自定义对话框的方法
    回调函数
    ObjectiveC 内存管理(转)
    mac 密码输入框控制——只能输入数字和字母,禁止特殊字符的输入
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/10064901.html
Copyright © 2011-2022 走看看