zoukankan      html  css  js  c++  java
  • BackgroundWorkerHelper

    public static class BackgroundWorkerHelper
        {
            public static void Run(DoWorkEventHandler doWork,
                                RunWorkerCompletedEventHandler completed = null,
                                ProgressChangedEventHandler progressChanged = null)
            {
                using (var backgroundWorker = new BackgroundWorker())
                {
                    backgroundWorker.DoWork += doWork;
                    if (completed != null)
                        backgroundWorker.RunWorkerCompleted += completed;
                    if (progressChanged != null)
                    {
                        backgroundWorker.WorkerReportsProgress = true;
                        backgroundWorker.ProgressChanged += progressChanged;
                    }
                    backgroundWorker.RunWorkerAsync();
                }
            }
        }
    
    
        public static class BackgroundWorkerHelperOrgainal
        {
            public static BackgroundWorker backgroundWorker { get; set; }
            public static void Run(DoWorkEventHandler doWork,
                                RunWorkerCompletedEventHandler completed = null,
                                ProgressChangedEventHandler progressChanged = null)
            {
                backgroundWorker = new BackgroundWorker();
                backgroundWorker.WorkerReportsProgress = true;
                backgroundWorker.WorkerSupportsCancellation = true;
                backgroundWorker.DoWork += doWork;
                if (completed != null)
                    backgroundWorker.RunWorkerCompleted += completed;
                if (progressChanged != null)
                {
                    backgroundWorker.WorkerReportsProgress = true;
                    backgroundWorker.ProgressChanged += progressChanged;
                }
                if (!backgroundWorker.IsBusy)
                    backgroundWorker.RunWorkerAsync();
    
            }
        }
     private void doTime()
            {
                try
                {
                    int mm = int.Parse(this.textBox1.Text.Trim());
    
                    BackgroundWorkerHelper.Run((s, e) =>
                    {
                        while (1 == 1)
                        {
                            try
                            {
                               
                            }
                            catch (Exception ex)
                            {
    
                            }
                        }
    
    
    
                    },
                    (s, e) =>
                    {
    
                    });
    
    
    
                }
                catch (Exception ex)
                {
                    ;
                }
                finally
                {
    
                }
            }

     BackgroundWorkerHelper.Run(
                          (s, e) =>
                          {
                              ReturnData rd = new ReturnData();//接收的
                              try
                              {
                                  try
                                  {
                                      rd = PlugRemote.GetInstance().GetAllCusmail(sd);
                                  }
                                  catch (Exception ex)
                                  {
                                      rd.state = false;
                                      rd.Info = ex.Message;
                                  }
                                  e.Result = rd;
                              }
                              catch (Exception ex)
                              {
                                  rd.state = false;
                                  rd.Info = ex.Message;
                                  e.Result = rd;
                              }
                          },
                          (s, e) =>
                          {
                              ReturnData rd = (ReturnData)e.Result;
                              if (!rd.state)
                              {
                                  this.ShowMessage(rd.Info, 1);
                                  return;
                              }
                              pagerControl1.DrawControl(rd.Count);//更新分页控件显示。
                              ReturnData<List<tms_cusmail>> rdt = new ReturnData<List<tms_cusmail>>(rd);
                              this.gridControl1.DataSource = rdt.t;
    
                          });
    BackgroundWorkerHelperOrgainal.Run((s, e) =>
                    {
                        BackgroundWorker bg = (BackgroundWorker)s;
                        foreach (var item in listvgs_real)
                        {
                            bg.ReportProgress(0, item);
                            Thread.Sleep(30);
                        }
    
                    },
                    (s, e) =>
                    {
                        isok = true;
                    },
                    (s, e) =>
                    {
                        if (e.ProgressPercentage == 0)
                        {
                            if (e.UserState != null)
                            {
                                var item = (vgs_real)e.UserState;
                                PointLatLng pl = new PointLatLng(item.OffsetLat, item.OffsetLng);
                                GMapMarkerDirection markerlast = new GMapMarkerDirection(new PointLatLng(item.OffsetLat, item.OffsetLng), Properties.Resources.carsmall, (float)item.Angle, 16, 16);
                                markerlast.IsHitTestVisible = true;
                                markerlast.ToolTipMode = MarkerTooltipMode.Always;
                                markerlast.ToolTipText = string.Format("车速:{0}
    地点{1}", item.VDRspeed, item.Address);
                                routesOverlay.Markers.Clear();
                                routesOverlay.Markers.Add(markerlast);
    
                                gmap.Position = pl;
    
                            }
    
                        }
                    });
  • 相关阅读:
    Python排序算法(一)——快速排序
    jupyter运行py文件(py文件和ipynb文件互转)
    Jupyter notebook工具栏隐藏和jupyter notebook主题更改
    Python中print和return的区别
    500 : Internal Server Error(jupyter)
    PEP8 python规范神器
    Python分析微信好友性别比例和省份城市分布比例
    xpath 的使用
    scrapy实验1 爬取中国人寿官网新闻,保存为xml
    数据可视化matplotlib、seaborn、pydotplus
  • 原文地址:https://www.cnblogs.com/wangchuang/p/11041696.html
Copyright © 2011-2022 走看看