一天中的特定时间后如何执行代码? [英] How to execute code after a certain time of day?

查看:63
本文介绍了一天中的特定时间后如何执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要创建一个函数,在一天中的特定时间后执行该函数.例如:在下午5:30之后执行一些代码.我试过比较两个时间跨度值,但没有用.它甚至在指定时间之前执行代码.我正在使用计时器.有任何想法吗?

Hi,
I need to create a function where it executes something after a certain time of day. For example : execute some code after 5:30 PM. I''ve tried comparing two timespan values but it doesn''t work. It executes the code even before the designated time. I''m using a timer. Any ideas?

推荐答案

您可以使用窗口服务在特定时间启动和处理某些特定任务.这是一个很好的例子.

http://www.c-sharpcorner.com/UploadFile/prvn_131971/BirthdayWishScheduler02022006012557AM /a> [ ^ ]
You can have window service to start and process some specific task on specific time. Here is a good example.

http://www.c-sharpcorner.com/UploadFile/prvn_131971/BirthdayWishScheduler02022006012557AM/BirthdayWishScheduler.aspx[^]


除了Kiran的解决方案:

有一个更简单的解决方案.

您还可以使用可用的计划程序服务.要安排代码运行,请使用Windows命令schtasks.exeat.exe.
参见:
http://en.wikipedia.org/wiki/At_(Windows) [ http://en.wikipedia.org/wiki/Schtasks [ http://msdn.microsoft.com/en-us/library/bb736357 (v = vs.85).aspx [ http://technet.microsoft.com/en-us/library/bb490866.aspx [ ^ ].

有关任务计划程序的更多信息:
http://msdn.microsoft.com/en-us/library/aa383614 (v = VS.85).aspx [ http://msdn.microsoft.com/en-us/library/aa383608 (v = VS.85).aspx [
In addition to the solution by Kiran:

There is a much simpler solution.

You can also use available Scheduler Service. To schedule a run of your code, use Windows command schtasks.exe or at.exe.
See:
http://en.wikipedia.org/wiki/At_(Windows)[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://msdn.microsoft.com/en-us/library/bb736357(v=vs.85).aspx[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^].

More on Task Scheduler:
http://msdn.microsoft.com/en-us/library/aa383614(v=VS.85).aspx[^],
http://msdn.microsoft.com/en-us/library/aa383608(v=VS.85).aspx[^].

—SA


这篇关于一天中的特定时间后如何执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆