public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append("在" + ServiceBase.FormatDateTime(BeginTime) + "开始执行"); if (RepeatPeriod != null) { sb.Append(",每隔" + RepeatPeriod.Value.ToString("h'小时'm'分's'秒'") + "执行一次"); } if (RepeatUntil != null) { sb.Append(",持续" + RepeatUntil.Value.ToString("h'小时'm'分钟's'秒后'") + "不再重复执行"); } if (EndTime != null) { sb.Append(",计划于" + ServiceBase.FormatDateTime(EndTime.Value) + "到期"); } return(sb.ToString()); }
/// <summary> /// 获取当前服务的执行状态名称 /// </summary> void updateServiceStatus(ScheduledServiceStatus serviceStatus, bool hasError = false) { //如果要更新为等待状态且没有开启自动执行功能,则认为服务已停止,否则更新为指定状态 if (serviceStatus == ScheduledServiceStatus.Waitting) //更新为等待状态时,需要进行特殊处理 { if (ServiceStatus == ScheduledServiceStatus.Stopping || willFinish) //由停止中的状态而来或本次运行已经是最后一次运行,说明任务将要结束 { this.ServiceStatus = ScheduledServiceStatus.Stopped; } else { this.ServiceStatus = ScheduledServiceStatus.Waitting; } } else { this.ServiceStatus = serviceStatus; } //更新控件状态 string statusName; string buttonText; bool operationEnabled; Color statusColor; string statusToolTip; switch (ServiceStatus) { case ScheduledServiceStatus.Stopped: if (hasError) { statusName = "已停止,有错误"; statusColor = Color.Red; } else { statusName = "已停止"; statusColor = Color.Black; } buttonText = "启用"; operationEnabled = true; manageScheduleEnabled = true; statusToolTip = null; break; case ScheduledServiceStatus.Waitting: if (hasError) { statusName = "等待运行,有错误"; statusColor = Color.Red; } else { statusName = "等待运行"; statusColor = Color.LimeGreen; } buttonText = "停用"; operationEnabled = true; manageScheduleEnabled = false; statusToolTip = "下次执行时间:" + ServiceBase.FormatDateTime((from schedule in enabledSchedules select schedule.ArrangedTime).Min()); break; case ScheduledServiceStatus.Running: statusName = "正在运行"; statusColor = Color.Green; buttonText = "停用"; operationEnabled = canbeCancelled; manageScheduleEnabled = false; statusToolTip = null; break; case ScheduledServiceStatus.Stopping: statusName = "正在停用"; statusColor = Color.DarkGray; buttonText = "停用"; operationEnabled = false; manageScheduleEnabled = false; statusToolTip = null; break; default: statusName = "未知状态"; buttonText = "未知"; statusColor = Color.Yellow; operationEnabled = false; manageScheduleEnabled = false; statusToolTip = null; break; } lStatus.Text = statusName; lStatus.ForeColor = statusColor; bOperation.Text = buttonText; bOperation.Enabled = operationEnabled; ttMain.SetToolTip(lStatus, statusToolTip); logInfo(statusName); }