Windows 调度程序和C#
我有一个用 C# 编写的脚本(ASP.NET 应用程序的一部分),如果到达预订的结束日期,该脚本将重置数字。我想自动化该过程,因此每次到达预订结束日期时,它都会发送一封电子邮件,通知该期限已过期,并执行我的脚本来重置计数器。
听说可以使用Windows Scheduler?我知道 cron 非常适合这项工作,但不幸的是我使用的当然是 Windows。任何有关如何实现上述任务自动化的提示将不胜感激。
I have a script I wrote in C# (part of a ASP.NET application) that would reset a number if the end date of a booking is reached. I would like to automate the process, so each time an end date of booking is reached, it will send an email notifying that period is expired and also execute my script to reset the counter.
I heard that Windows Scheduler could be used? I know cron is perfect for this job, but unfortunately it is windows of course I am using. Any hints on what to do for automation of tasks above would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前往:
创建一个新任务并指定日期、时间、频率等。
可以从您在上面步骤中创建的任务中调用您的 C# 程序。
Go to:
Create a new task and specify date, time, frequency, etc.
Your C# program can be invoked from the task you created on the step above.
通常,我要么编写一个小型 C# 控制台应用程序,要么使用 C# 脚本 来实现此目的。如果我能理解 Powershell 的“奇怪”(恕我直言)语法,这将是更好的方法去做。
无论您使用什么,通常不能使用包含在 ASP.NET 应用程序中的 C# 代码。相反,请将代码提取到上述可能性之一,并使用任务计划程序创建具有以下选项的任务:
您可以将任务安排为例如每n 分钟/小时运行一次,即使没有用户登录也是如此。
Usually, I either write a small C# console application or use C# Script for this. If I would understand the "strange" (IMHO) syntax of Powershell, this would be the preferable way to do.
No matter what you use, you usually cannot use C# code that is included inside an ASP.NET application. Instead, extract the code into one of the possibilities above and use the Task Scheduler to create a task with the following options:
You could schedule the task to e.g. run every n minutes/hours, even if no user is logged in.