本文介绍了如何安排窗口服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我们创建了一个web服务,根据时间...我们在webconfig中传递参考下面的代码 < add key = 模式 value = 每日 / > <! - < add key =模式值=间隔/> - > < add key = IntervalMinutes value = 1 / > < add key = ScheduledTime 值 = 18: 30 / > 在Onstart事件中,我创建了将更新数据库的方法 public void ScheduleService() { 尝试 { Schedular = new Timer(新的TimerCallback(SchedularCallback)); string mode = ConfigurationManager。 AppSettings [Mode]。ToUpper(); this.WriteToFile(简单服务模式:+模式+{0}); //设置默认时间。 DateTime scheduledTime = DateTime.MinValue; if(mode ==DAILY ) { //从AppSettings获取预定时间。 scheduledTime = DateTime.Parse(System.Configuration.ConfigurationManager.AppSettings [ ScheduledTime]); if(DateTime.Now>预定时间) { this.pulldata(); //如果通过预定时间,则设定第二天的时间表。 scheduledTime = scheduledTime.AddDays(1); } else { if (DateTime.Now == scheduledTime) { this.pulldata(); //如果通过预定时间,则为第二天。 scheduledTime = scheduledTime.AddDays(1); } } } if(mode.ToUpper()==INTERVAL) { //在几分钟内获取间隔来自AppSettings。 int intervalMinutes = Convert.ToInt32(ConfigurationManager.AppSettings [IntervalMinutes]); //通过添加间隔来设置预定时间当前时间。 scheduledTime = DateTime.Now.AddMinutes(intervalMinutes); if(DateTime.Now> scheduledTime) { //如果超过预定时间,则为下一个时间间隔设置时间表。 scheduledTime = scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan timeSpan = scheduledTime.Subtract(DateTime.Now); string schedule = string.Format({0} day(s){1}小时{2}分钟{3}秒(s),timeSpan.Days,timeSpan.Hours, timeSpan.Minutes,timeSpan.Seconds); this.WriteToFile(简单服务计划在之后运行:+ schedule +{0}); //获取预定时间和当前时间之间的分钟数。 int dueTime = Convert.ToInt32(timeSpan.TotalMilliseconds); //更改计时器的截止时间。 Schedular.Change(dueTime,Timeout.Infinite); } catch(例外情况) { WriteToFile(简单服务错误:{0}+ ex.Message + ex.StackTrace); //停止Windows服务。 using(System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(SimpleService)) { serviceController.Stop(); } } } 之后构建我在动作按钮中传递任务计划中的exe,我收到错误事件103 .. 如何解决此错误。 任何帮助解决方案 We have created a webservice which will according to the time .. which we pass in webconfig refer to code below<add key ="Mode" value ="Daily"/> <!-- <add key ="Mode" value ="Interval"/>--> <add key ="IntervalMinutes" value ="1"/> <add key ="ScheduledTime" value ="18:30"/>On the Onstart event i have created method which will update the database public void ScheduleService() { try { Schedular = new Timer(new TimerCallback(SchedularCallback)); string mode = ConfigurationManager.AppSettings["Mode"].ToUpper(); this.WriteToFile("Simple Service Mode: " + mode + " {0}"); //Set the Default Time. DateTime scheduledTime = DateTime.MinValue; if (mode == "DAILY") { //Get the Scheduled Time from AppSettings. scheduledTime = DateTime.Parse(System.Configuration.ConfigurationManager.AppSettings["ScheduledTime"]); if (DateTime.Now > scheduledTime) { this.pulldata(); //If Scheduled Time is passed set Schedule for the next day. scheduledTime = scheduledTime.AddDays(1); } else { if (DateTime.Now == scheduledTime) { this.pulldata(); //If Scheduled Time is passed set Schedule for the next day. scheduledTime = scheduledTime.AddDays(1); } } } if (mode.ToUpper() == "INTERVAL") { //Get the Interval in Minutes from AppSettings. int intervalMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["IntervalMinutes"]); //Set the Scheduled Time by adding the Interval to Current Time. scheduledTime = DateTime.Now.AddMinutes(intervalMinutes); if (DateTime.Now > scheduledTime) { //If Scheduled Time is passed set Schedule for the next Interval. scheduledTime = scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan timeSpan = scheduledTime.Subtract(DateTime.Now); string schedule = string.Format("{0} day(s) {1} hour(s) {2} minute(s) {3} seconds(s)", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); this.WriteToFile("Simple Service scheduled to run after: " + schedule + " {0}"); //Get the difference in Minutes between the Scheduled and Current Time. int dueTime = Convert.ToInt32(timeSpan.TotalMilliseconds); //Change the Timer's Due Time. Schedular.Change(dueTime, Timeout.Infinite); } catch (Exception ex) { WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace); //Stop the Windows Service. using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService")) { serviceController.Stop(); } } }after the build I m passing the exe in task schedular in the action button ,i received the error Event 103 ..how to solve this error.any help 解决方案 这篇关于如何安排窗口服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-09 03:30