Exemplo n.º 1
0
        protected void btnEstimate_Click(object sender, EventArgs e)
        {
            try
            {
                JobSchedule schedule = GetSchedule();
                Stopwatch   sw       = new Stopwatch();
                TimeSpan    timeout  = TimeSpan.FromSeconds(10);

                sw.Start();

                List <DateTime> estimateTime = schedule.EstimateExecuteTime(TimeSpan.FromSeconds(30), 20, timeout);


                for (int i = estimateTime.Count - 1; i >= 0; i--)
                {
                    if (estimateTime[i] > schedule.NormalizedEndTime)
                    {
                        estimateTime.RemoveAt(i);
                    }
                }

                StringBuilder strB = new StringBuilder();

                foreach (DateTime time in estimateTime)
                {
                    if (strB.Length > 0)
                    {
                        strB.Append("\n");
                    }

                    strB.Append(time.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                sw.Stop();

                if (sw.Elapsed >= timeout)
                {
                    strB.Append("超时时间已到,无法计算出预估时间");
                }
                else
                if (strB.Length == 0)
                {
                    strB.Append("无法计算出预估时间");
                }

                WebUtility.ShowClientMessage(strB.ToString(), string.Empty, "预估执行时间");
            }
            catch (Exception ex)
            {
                WebUtility.ShowClientError(ex.Message, ex.StackTrace, "错误");
            }
            finally
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "resetButtons", "top.document.getElementById('resetButton').click();", true);
            }
        }