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

  • 相关阅读:
    xlrd模块
    魔法路由ViewSetMixin
    AES加密
    orm的增删改查
    引入方式+样式+选择器
    视图+sql注入+事务+存储过程
    mysql用户管理+pymysql模块
    记录的详细操作
    约束
    一次http请求参数问题
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/10064901.html
Copyright © 2011-2022 走看看