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;
    
                            }
    
                        }
                    });
  • 相关阅读:
    zbb20190605 maven windows配置maven私服以及使用
    zbb20190528 城市经纬度json
    zbb20190528 adcode 城市编码
    zbb20190430 springboot 配置alimq
    zbb20190408 spring-boot-maven-plugin 插件的作用详解
    zbb20190131 Mybatis,mysql映射文件<!CDATA[[]]> 转义问题
    Spring Boot (29) 定时任务
    Spring Boot (28) actuator与spring-boot-admin
    Spring Boot (27) actuator服务监控与管理
    Java 8
  • 原文地址:https://www.cnblogs.com/wangchuang/p/11041696.html
Copyright © 2011-2022 走看看