zoukankan      html  css  js  c++  java
  • 执行异步任务,并记录时间

    var stopwatch = Stopwatch.StartNew();
            stopwatch.Start();
    
            try
            {
                DataTable dt = DbHelperSQL.Query("select CampaignCode from Test.dbo.[F2SMS04] where ISNULL(Mobile,'') != ''  group by CampaignCode").Tables[0];
    
                if (dt != null && dt.Rows.Count > 0)
                {
                    Task[] tasks = new Task[dt.Rows.Count];
    
                    for (int i = dt.Rows.Count - 1; i >= 0; i--)
                    {
                        DataRow dataRow = dt.Rows[i];
    
                        string str = dataRow["CampaignCode"].ToString();
                        var task1 = Task.Factory.StartNew(() => { ShowData("F1", "[F2SMS04]", str); });
                        tasks[i] = task1;
                    }
                    Task.WaitAll(tasks );
                }
                //var task1 = Task.Factory.StartNew(() => { ShowData("F1", "[F2SMS04]"); });
                //var task2 = Task.Factory.StartNew(() => { ShowData("F2", "[27F2Y1983]"); });
                //var task3 = Task.Factory.StartNew(() => { ShowData("F3", "[33F3N1850]"); });
                //Task.WaitAll(new[] { task1 });
                gvResult.DataSource = dtShow;
                gvResult.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("任务异常:" + ex.Message + "<br/>");
            }
    
            // cde.Wait();
            stopwatch.Stop();
            lblTip.Text = "ShortUrl生成成功" + "生成时间:" + stopwatch.ElapsedMilliseconds;
  • 相关阅读:
    030-B+树(三)
    028-B+树(一)
    027-B树(二)
    026-B树(一)
    025-红黑树(六)
    024-红黑树(五)
    023-红黑树(四)
    022-红黑树(三)
    021-红黑树(二)
    020-红黑树(一)
  • 原文地址:https://www.cnblogs.com/itjeff/p/6627451.html
Copyright © 2011-2022 走看看