Today we have built a console application for running the scheduled tasks for our ASP.NET website. But I think this approach is a bit error prone and difficult to maintain. How do you execute your scheduled task (in an windows/IIS/ASP.NET environment)
今天我们已经构建了一个控制台应用程序来运行我们的ASP的预定任务。网的网站。但我认为这种方法容易出错,很难维护。如何执行计划任务(在windows/IIS/ASP中)。网络环境)
Update:
更新:
Examples of tasks:
任务的例子:
- Sending email from an email-queue in the database
- 从数据库中的邮件队列发送电子邮件
- Removing outdated objects from the database
- 从数据库中删除过时的对象
- Retrieving stats from Google AdWords and fill a table in the database.
- 从谷歌AdWords检索统计数据并在数据库中填充一个表。
16 个解决方案
#1
68
All of my tasks (which need to be scheduled) for a website are kept within the website and called from a special page. I then wrote a simple Windows service which calls this page every so often. Once the page runs it returns a value. If I know there is more work to be done, I run the page again, right away, otherwise I run it in a little while. This has worked really well for me and keeps all my task logic with the web code. Before writing the simple Windows service, I used Windows scheduler to call the page every x minutes.
我为一个网站所做的所有任务(需要安排)都保存在这个网站中,并从一个特殊的页面调用。然后我编写了一个简单的Windows服务,它经常调用这个页面。一旦页面运行,它将返回一个值。如果我知道还有更多的工作要做,我就重新运行这个页面,否则我将在稍后运行它。这对我来说非常有效,并且使我所有的任务逻辑与web代码保持一致。在编写简单的Windows服务之前,我使用Windows调度器每隔x分钟调用一次页面。
Another convenient way to run this is to use a monitoring service like Pingdom. Point their http check to the page which runs your service code. Have the page return results which then can be used to trigger Pingdom to send alert messages when something isn't right.
另一种方便的运行方式是使用类似Pingdom的监视服务。将他们的http检查指向运行您的服务代码的页面。让页面返回结果,然后可以使用该结果来触发Pingdom,以便在出现错误时发送警报消息。
#2
117
This technique by Jeff Atwood for * is the simplest method I've come across. It relies on the "cache item removed" callback mechanism build into ASP.NET's cache system
Jeff Atwood的*技巧是我遇到的最简单的方法。它依赖于在ASP中构建的“缓存项删除”回调机制。净的缓存系统
Update: * has outgrown this method. It only works while the website is running but it's a very simple technique that is useful for many people.
更新:*已经超越了这个方法。它只在网站运行时有效,但它是一种非常简单的技术,对很多人都很有用。
Also check out Quartz.NET
也看看Quartz.NET
#3
29
Create a custom Windows Service.
创建自定义Windows服务。
I had some mission-critical tasks set up as scheduled console apps and found them difficult to maintain. I created a Windows Service with a 'heartbeat' that would check a schedule in my DB every couple of minutes. It's worked out really well.
我有一些任务关键任务设置为预定的控制台应用程序,发现它们很难维护。我用“心跳”创建了一个Windows服务,每隔几分钟就会检查我的数据库中的日程表。结果真的很好。
Having said that, I still use scheduled console apps for most of my non-critical maintenance tasks. If it ain't broke, don't fix it.
话虽如此,我仍然在大多数非关键的维护任务中使用预定的控制台应用程序。如果没有坏,就不要修理。
#4
17
I've found this to be easy for all involved:
我发现这对所有人来说都很容易:
- Create a webservice method such as DoSuchAndSuchProcess
- 创建一个webservice方法,例如DoSuchAndSuchProcess。
- Create a console app that calls this webmethod.
- 创建一个名为webmethod的控制台应用程序。
- Schedule the console app in the task scheduler.
- 在任务调度程序中调度控制台应用程序。
Using this methodology all of the business logic is contained in your web app, but you have the reliability of the windows task manager, or any other commercial task manager to kick it off and record any return information such as an execution report. Using a web service instead of posting to a page has a bit of an advantage because it's easier to get return data from a webservice.
使用这种方法,所有的业务逻辑都包含在web应用程序中,但是您具有windows任务管理器或任何其他商业任务管理器的可靠性,可以启动它并记录任何返回信息,如执行报告。使用web服务而不是发布到页面有一点好处,因为从web服务获取返回数据更容易。
#5
10
Why reinvent the wheel, use the Threading and the Timer class.
为什么要重新发明*,使用线程和定时器类。
protected void Application_Start()
{
Thread thread = new Thread(new ThreadStart(ThreadFunc));
thread.IsBackground = true;
thread.Name = "ThreadFunc";
thread.Start();
}
protected void ThreadFunc()
{
System.Timers.Timer t = new System.Timers.Timer();
t.Elapsed += new System.Timers.ElapsedEventHandler(TimerWorker);
t.Interval = 10000;
t.Enabled = true;
t.AutoReset = true;
t.Start();
}
protected void TimerWorker(object sender, System.Timers.ElapsedEventArgs e)
{
//work args
}
#6
7
Use Windows Scheduler to run a web page.
使用Windows调度器运行网页。
To prevent malicous user or search engine spiders to run it, when you setup the scheduled task, simply call the web page with a querystring, ie : mypage.aspx?from=scheduledtask
为了防止恶意用户或搜索引擎爬行器运行它,在设置计划任务时,只需使用一个querystring调用web页面,即:mypage.aspx?from=scheduledtask
Then in the page load, simply use a condition : if (Request.Querystring["from"] == "scheduledtask") { //executetask }
然后在页面加载中,只需使用一个条件:if(请求)。Querystring["from"] = "scheduledtask") {// /executetask}
This way no search engine spider or malicious user will be able to execute your scheduled task.
这样,搜索引擎蜘蛛或恶意用户将无法执行您预定的任务。
#7
4
This library works like a charm http://www.codeproject.com/KB/cs/tsnewlib.aspx
这个库的工作方式类似于一个咒语http://www.codeproject.com/KB/cs/tsnewlib.aspx
It allows you to manage Windows scheduled tasks directly through your .NET code.
它允许您直接通过. net代码管理Windows计划任务。
#8
3
Additionally, if your application uses SQL SERVER you can use the SQL Agent to schedule your tasks. This is where we commonly put re-occurring code that is data driven (email reminders, scheduled maintenance, purges, etc...). A great feature that is built in with the SQL Agent is failure notification options, which can alert you if a critical task fails.
此外,如果应用程序使用SQL SERVER,您可以使用SQL代理来调度任务。这就是我们通常放置数据驱动的重用代码的地方(电子邮件提醒、计划维护、清理等等)。与SQL代理一起构建的一个很棒的特性是失败通知选项,它可以在关键任务失败时提醒您。
#9
2
I'm not sure what kind of scheduled tasks you mean. If you mean stuff like "every hour, refresh foo.xml" type tasks, then use the Windows Scheduled Tasks system. (The "at" command, or via the controller.) Have it either run a console app or request a special page that kicks off the process.
我不知道你指的是什么样的计划任务。如果你的意思是“每小时刷新一次”。xml“类型任务,然后使用Windows计划任务系统。(“at”命令,或通过控制器)让它运行一个控制台应用程序,或者请求一个特殊的页面来启动进程。
Edit: I should add, this is an OK way to get your IIS app running at scheduled points too. So suppose you want to check your DB every 30 minutes and email reminders to users about some data, you can use scheduled tasks to request this page and hence get IIS processing things.
编辑:我应该补充一下,这也是让你的IIS应用在预定时间运行的好方法。因此,假设您想每30分钟检查一次数据库,并向用户发送一些关于数据的电子邮件提醒,您可以使用预定的任务来请求此页面,从而获得IIS处理。
If your needs are more complex, you might consider creating a Windows Service and having it run a loop to do whatever processing you need. This also has the benefit of separating out the code for scaling or management purposes. On the downside, you need to deal with Windows services.
如果您的需求比较复杂,您可以考虑创建一个Windows服务,并让它运行一个循环来执行您需要的任何处理。这还可以将代码分离出来,用于扩展或管理目的。缺点是,您需要处理Windows服务。
#10
2
If you own the server you should use the windows task scheduler. Use AT /? from the command line to see the options.
如果您拥有服务器,您应该使用windows任务调度器。使用在/ ?从命令行中查看选项。
Otherwise, from a web based environment, you might have to do something nasty like set up a different machine to make requests to a certain page on a timed interval.
否则,在基于web的环境中,您可能需要做一些令人讨厌的事情,比如设置一个不同的机器,在一个定时间隔向某个页面发出请求。
#11
2
I've used Abidar successfully in an ASP.NET project (here's some background information).
我已经在ASP中成功地使用了Abidar。NET项目(这里有一些背景信息)。
The only problem with this method is that the tasks won't run if the ASP.NET web application is unloaded from memory (ie. due to low usage). One thing I tried is creating a task to hit the web application every 5 minutes, keeping it alive, but this didn't seem to work reliably, so now I'm using the Windows scheduler and basic console application to do this instead.
这种方法的唯一问题是,如果使用ASP,任务将不会运行。NET web应用程序从内存中卸载。由于低的使用)。我尝试过的一件事是每5分钟创建一个任务来访问web应用程序,使其保持活动状态,但这似乎不能可靠地工作,所以现在我使用Windows调度器和基本控制台应用程序来实现这一点。
The ideal solution is creating a Windows service, though this might not be possible (ie. if you're using a shared hosting environment). It also makes things a little easier from a maintenance perspective to keep things within the web application.
理想的解决方案是创建一个Windows服务,尽管这可能是不可能的。如果您使用的是共享主机环境)。从维护的角度来看,它也使得在web应用程序中保存东西变得更加容易。
#12
1
Here's another way:
这是另一种方式:
1) Create a "heartbeat" web script that is responsible for launching the tasks if they are DUE or overdue to be launched.
1)创建一个“heartbeat”web脚本,负责在任务到期或过期时启动它们。
2) Create a scheduled process somewhere (preferrably on the same web server) that hits the webscript and forces it to run at a regular interval. (e.g. windows schedule task that quietly launches the heatbeat script using IE or whathaveyou)
2)在某个地方(最好是在同一web服务器上)创建一个计划进程,该进程将访问webscript并强制它以常规间隔运行。(例如,windows调度任务,使用IE或其他工具悄悄地启动heatbeat脚本)
The fact that the task code is contained within a web script is purely for the sake of keeping the code within the web application code-base (the assumption is that both are dependent on each other), which would be easier for web developers to manage.
任务代码包含在web脚本中这一事实纯粹是为了将代码保存在web应用程序代码库中(假设两者都相互依赖),这对于web开发人员来说更容易管理。
The alternate approach is to create an executable server script / program that does all the schedule work itself and run the executable itself as a scheduled task. This can allow for fundamental decoupling between the web application and the scheduled task. Hence if you need your scheduled tasks to run even in the even that the web app / database might be down or inaccessible, you should go with this approach.
另一种方法是创建一个可执行的服务器脚本/程序,该脚本执行所有调度工作,并将可执行文件本身作为调度任务运行。这可以实现web应用程序和计划任务之间的基本解耦。因此,如果您需要您的调度任务运行,即使web应用程序/数据库可能会下降或无法访问,您也应该采用这种方法。
#13
1
You can easily create a Windows Service that runs code on interval using the 'ThreadPool.RegisterWaitForSingleObject' method. It is really slick and quite easy to get set up. This method is a more streamlined approach then to use any of the Timers in the Framework.
您可以轻松创建一个Windows服务,该服务使用“ThreadPool”以间隔运行代码。RegisterWaitForSingleObject”方法。它非常光滑,而且很容易安装。该方法是一种更精简的方法,然后在框架中使用任何计时器。
Have a look at the link below for more information:
查看下面的链接了解更多信息:
Running a Periodic Process in .NET using a Windows Service:
http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic-process-in-net-using.html
使用Windows服务在。net中运行定期进程:http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic- processin -net- use .html
#14
0
We use console applications also. If you use logging tools like Log4net you can properly monitor their execution. Also, I'm not sure how they are more difficult to maintain than a web page, given you may be sharing some of the same code libraries between the two if it is designed properly.
我们还使用控制台应用程序。如果您使用Log4net之类的日志工具,您可以正确地监视它们的执行。此外,我不确定它们如何比web页面更难维护,因为如果设计得当,您可能会在两者之间共享一些相同的代码库。
If you are against having those tasks run on a timed basis, you could have a web page in your administrative section of your website that acts as a queue. User puts in a request to run the task, it in turn inserts a blank datestamp record on MyProcessQueue table and your scheduled task is checking every X minutes for a new record in MyProcessQueue. That way, it only runs when the customer wants it to run.
如果您反对让这些任务按定时运行,那么您可以在您的网站的管理部分有一个作为队列的web页面。用户输入一个运行任务的请求,然后在MyProcessQueue表上插入一个空白的datestamp记录,您的计划任务每X分钟检查一次MyProcessQueue中的新记录。这样,它只在客户希望运行时才运行。
Hope those suggestions help.
希望这些建议的帮助。
#15
0
One option would be to set up a windows service and get that to call your scheduled task.
一个选项是设置一个windows服务,并让它调用您的计划任务。
In winforms I've used Timers put don't think this would work well in ASP.NET
在winforms中,我使用了timer put,但我不认为它在ASP.NET中工作得很好
#16
-1
A New Task Scheduler Class Library for .NET
.NET的一个新的任务调度器类库
Note: Since this library was created, Microsoft has introduced a new task scheduler (Task Scheduler 2.0) for Windows Vista. This library is a wrapper for the Task Scheduler 1.0 interface, which is still available in Vista and is compatible with Windows XP, Windows Server 2003 and Windows 2000.
注意:自从这个库创建以来,微软已经为Windows Vista引入了一个新的任务调度器(任务调度器2.0)。这个库是任务调度器1.0接口的包装器,它在Vista中仍然可用,与Windows XP、Windows Server 2003和Windows 2000兼容。
http://www.codeproject.com/KB/cs/tsnewlib.aspx
http://www.codeproject.com/KB/cs/tsnewlib.aspx
#1
68
All of my tasks (which need to be scheduled) for a website are kept within the website and called from a special page. I then wrote a simple Windows service which calls this page every so often. Once the page runs it returns a value. If I know there is more work to be done, I run the page again, right away, otherwise I run it in a little while. This has worked really well for me and keeps all my task logic with the web code. Before writing the simple Windows service, I used Windows scheduler to call the page every x minutes.
我为一个网站所做的所有任务(需要安排)都保存在这个网站中,并从一个特殊的页面调用。然后我编写了一个简单的Windows服务,它经常调用这个页面。一旦页面运行,它将返回一个值。如果我知道还有更多的工作要做,我就重新运行这个页面,否则我将在稍后运行它。这对我来说非常有效,并且使我所有的任务逻辑与web代码保持一致。在编写简单的Windows服务之前,我使用Windows调度器每隔x分钟调用一次页面。
Another convenient way to run this is to use a monitoring service like Pingdom. Point their http check to the page which runs your service code. Have the page return results which then can be used to trigger Pingdom to send alert messages when something isn't right.
另一种方便的运行方式是使用类似Pingdom的监视服务。将他们的http检查指向运行您的服务代码的页面。让页面返回结果,然后可以使用该结果来触发Pingdom,以便在出现错误时发送警报消息。
#2
117
This technique by Jeff Atwood for * is the simplest method I've come across. It relies on the "cache item removed" callback mechanism build into ASP.NET's cache system
Jeff Atwood的*技巧是我遇到的最简单的方法。它依赖于在ASP中构建的“缓存项删除”回调机制。净的缓存系统
Update: * has outgrown this method. It only works while the website is running but it's a very simple technique that is useful for many people.
更新:*已经超越了这个方法。它只在网站运行时有效,但它是一种非常简单的技术,对很多人都很有用。
Also check out Quartz.NET
也看看Quartz.NET
#3
29
Create a custom Windows Service.
创建自定义Windows服务。
I had some mission-critical tasks set up as scheduled console apps and found them difficult to maintain. I created a Windows Service with a 'heartbeat' that would check a schedule in my DB every couple of minutes. It's worked out really well.
我有一些任务关键任务设置为预定的控制台应用程序,发现它们很难维护。我用“心跳”创建了一个Windows服务,每隔几分钟就会检查我的数据库中的日程表。结果真的很好。
Having said that, I still use scheduled console apps for most of my non-critical maintenance tasks. If it ain't broke, don't fix it.
话虽如此,我仍然在大多数非关键的维护任务中使用预定的控制台应用程序。如果没有坏,就不要修理。
#4
17
I've found this to be easy for all involved:
我发现这对所有人来说都很容易:
- Create a webservice method such as DoSuchAndSuchProcess
- 创建一个webservice方法,例如DoSuchAndSuchProcess。
- Create a console app that calls this webmethod.
- 创建一个名为webmethod的控制台应用程序。
- Schedule the console app in the task scheduler.
- 在任务调度程序中调度控制台应用程序。
Using this methodology all of the business logic is contained in your web app, but you have the reliability of the windows task manager, or any other commercial task manager to kick it off and record any return information such as an execution report. Using a web service instead of posting to a page has a bit of an advantage because it's easier to get return data from a webservice.
使用这种方法,所有的业务逻辑都包含在web应用程序中,但是您具有windows任务管理器或任何其他商业任务管理器的可靠性,可以启动它并记录任何返回信息,如执行报告。使用web服务而不是发布到页面有一点好处,因为从web服务获取返回数据更容易。
#5
10
Why reinvent the wheel, use the Threading and the Timer class.
为什么要重新发明*,使用线程和定时器类。
protected void Application_Start()
{
Thread thread = new Thread(new ThreadStart(ThreadFunc));
thread.IsBackground = true;
thread.Name = "ThreadFunc";
thread.Start();
}
protected void ThreadFunc()
{
System.Timers.Timer t = new System.Timers.Timer();
t.Elapsed += new System.Timers.ElapsedEventHandler(TimerWorker);
t.Interval = 10000;
t.Enabled = true;
t.AutoReset = true;
t.Start();
}
protected void TimerWorker(object sender, System.Timers.ElapsedEventArgs e)
{
//work args
}
#6
7
Use Windows Scheduler to run a web page.
使用Windows调度器运行网页。
To prevent malicous user or search engine spiders to run it, when you setup the scheduled task, simply call the web page with a querystring, ie : mypage.aspx?from=scheduledtask
为了防止恶意用户或搜索引擎爬行器运行它,在设置计划任务时,只需使用一个querystring调用web页面,即:mypage.aspx?from=scheduledtask
Then in the page load, simply use a condition : if (Request.Querystring["from"] == "scheduledtask") { //executetask }
然后在页面加载中,只需使用一个条件:if(请求)。Querystring["from"] = "scheduledtask") {// /executetask}
This way no search engine spider or malicious user will be able to execute your scheduled task.
这样,搜索引擎蜘蛛或恶意用户将无法执行您预定的任务。
#7
4
This library works like a charm http://www.codeproject.com/KB/cs/tsnewlib.aspx
这个库的工作方式类似于一个咒语http://www.codeproject.com/KB/cs/tsnewlib.aspx
It allows you to manage Windows scheduled tasks directly through your .NET code.
它允许您直接通过. net代码管理Windows计划任务。
#8
3
Additionally, if your application uses SQL SERVER you can use the SQL Agent to schedule your tasks. This is where we commonly put re-occurring code that is data driven (email reminders, scheduled maintenance, purges, etc...). A great feature that is built in with the SQL Agent is failure notification options, which can alert you if a critical task fails.
此外,如果应用程序使用SQL SERVER,您可以使用SQL代理来调度任务。这就是我们通常放置数据驱动的重用代码的地方(电子邮件提醒、计划维护、清理等等)。与SQL代理一起构建的一个很棒的特性是失败通知选项,它可以在关键任务失败时提醒您。
#9
2
I'm not sure what kind of scheduled tasks you mean. If you mean stuff like "every hour, refresh foo.xml" type tasks, then use the Windows Scheduled Tasks system. (The "at" command, or via the controller.) Have it either run a console app or request a special page that kicks off the process.
我不知道你指的是什么样的计划任务。如果你的意思是“每小时刷新一次”。xml“类型任务,然后使用Windows计划任务系统。(“at”命令,或通过控制器)让它运行一个控制台应用程序,或者请求一个特殊的页面来启动进程。
Edit: I should add, this is an OK way to get your IIS app running at scheduled points too. So suppose you want to check your DB every 30 minutes and email reminders to users about some data, you can use scheduled tasks to request this page and hence get IIS processing things.
编辑:我应该补充一下,这也是让你的IIS应用在预定时间运行的好方法。因此,假设您想每30分钟检查一次数据库,并向用户发送一些关于数据的电子邮件提醒,您可以使用预定的任务来请求此页面,从而获得IIS处理。
If your needs are more complex, you might consider creating a Windows Service and having it run a loop to do whatever processing you need. This also has the benefit of separating out the code for scaling or management purposes. On the downside, you need to deal with Windows services.
如果您的需求比较复杂,您可以考虑创建一个Windows服务,并让它运行一个循环来执行您需要的任何处理。这还可以将代码分离出来,用于扩展或管理目的。缺点是,您需要处理Windows服务。
#10
2
If you own the server you should use the windows task scheduler. Use AT /? from the command line to see the options.
如果您拥有服务器,您应该使用windows任务调度器。使用在/ ?从命令行中查看选项。
Otherwise, from a web based environment, you might have to do something nasty like set up a different machine to make requests to a certain page on a timed interval.
否则,在基于web的环境中,您可能需要做一些令人讨厌的事情,比如设置一个不同的机器,在一个定时间隔向某个页面发出请求。
#11
2
I've used Abidar successfully in an ASP.NET project (here's some background information).
我已经在ASP中成功地使用了Abidar。NET项目(这里有一些背景信息)。
The only problem with this method is that the tasks won't run if the ASP.NET web application is unloaded from memory (ie. due to low usage). One thing I tried is creating a task to hit the web application every 5 minutes, keeping it alive, but this didn't seem to work reliably, so now I'm using the Windows scheduler and basic console application to do this instead.
这种方法的唯一问题是,如果使用ASP,任务将不会运行。NET web应用程序从内存中卸载。由于低的使用)。我尝试过的一件事是每5分钟创建一个任务来访问web应用程序,使其保持活动状态,但这似乎不能可靠地工作,所以现在我使用Windows调度器和基本控制台应用程序来实现这一点。
The ideal solution is creating a Windows service, though this might not be possible (ie. if you're using a shared hosting environment). It also makes things a little easier from a maintenance perspective to keep things within the web application.
理想的解决方案是创建一个Windows服务,尽管这可能是不可能的。如果您使用的是共享主机环境)。从维护的角度来看,它也使得在web应用程序中保存东西变得更加容易。
#12
1
Here's another way:
这是另一种方式:
1) Create a "heartbeat" web script that is responsible for launching the tasks if they are DUE or overdue to be launched.
1)创建一个“heartbeat”web脚本,负责在任务到期或过期时启动它们。
2) Create a scheduled process somewhere (preferrably on the same web server) that hits the webscript and forces it to run at a regular interval. (e.g. windows schedule task that quietly launches the heatbeat script using IE or whathaveyou)
2)在某个地方(最好是在同一web服务器上)创建一个计划进程,该进程将访问webscript并强制它以常规间隔运行。(例如,windows调度任务,使用IE或其他工具悄悄地启动heatbeat脚本)
The fact that the task code is contained within a web script is purely for the sake of keeping the code within the web application code-base (the assumption is that both are dependent on each other), which would be easier for web developers to manage.
任务代码包含在web脚本中这一事实纯粹是为了将代码保存在web应用程序代码库中(假设两者都相互依赖),这对于web开发人员来说更容易管理。
The alternate approach is to create an executable server script / program that does all the schedule work itself and run the executable itself as a scheduled task. This can allow for fundamental decoupling between the web application and the scheduled task. Hence if you need your scheduled tasks to run even in the even that the web app / database might be down or inaccessible, you should go with this approach.
另一种方法是创建一个可执行的服务器脚本/程序,该脚本执行所有调度工作,并将可执行文件本身作为调度任务运行。这可以实现web应用程序和计划任务之间的基本解耦。因此,如果您需要您的调度任务运行,即使web应用程序/数据库可能会下降或无法访问,您也应该采用这种方法。
#13
1
You can easily create a Windows Service that runs code on interval using the 'ThreadPool.RegisterWaitForSingleObject' method. It is really slick and quite easy to get set up. This method is a more streamlined approach then to use any of the Timers in the Framework.
您可以轻松创建一个Windows服务,该服务使用“ThreadPool”以间隔运行代码。RegisterWaitForSingleObject”方法。它非常光滑,而且很容易安装。该方法是一种更精简的方法,然后在框架中使用任何计时器。
Have a look at the link below for more information:
查看下面的链接了解更多信息:
Running a Periodic Process in .NET using a Windows Service:
http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic-process-in-net-using.html
使用Windows服务在。net中运行定期进程:http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic- processin -net- use .html
#14
0
We use console applications also. If you use logging tools like Log4net you can properly monitor their execution. Also, I'm not sure how they are more difficult to maintain than a web page, given you may be sharing some of the same code libraries between the two if it is designed properly.
我们还使用控制台应用程序。如果您使用Log4net之类的日志工具,您可以正确地监视它们的执行。此外,我不确定它们如何比web页面更难维护,因为如果设计得当,您可能会在两者之间共享一些相同的代码库。
If you are against having those tasks run on a timed basis, you could have a web page in your administrative section of your website that acts as a queue. User puts in a request to run the task, it in turn inserts a blank datestamp record on MyProcessQueue table and your scheduled task is checking every X minutes for a new record in MyProcessQueue. That way, it only runs when the customer wants it to run.
如果您反对让这些任务按定时运行,那么您可以在您的网站的管理部分有一个作为队列的web页面。用户输入一个运行任务的请求,然后在MyProcessQueue表上插入一个空白的datestamp记录,您的计划任务每X分钟检查一次MyProcessQueue中的新记录。这样,它只在客户希望运行时才运行。
Hope those suggestions help.
希望这些建议的帮助。
#15
0
One option would be to set up a windows service and get that to call your scheduled task.
一个选项是设置一个windows服务,并让它调用您的计划任务。
In winforms I've used Timers put don't think this would work well in ASP.NET
在winforms中,我使用了timer put,但我不认为它在ASP.NET中工作得很好
#16
-1
A New Task Scheduler Class Library for .NET
.NET的一个新的任务调度器类库
Note: Since this library was created, Microsoft has introduced a new task scheduler (Task Scheduler 2.0) for Windows Vista. This library is a wrapper for the Task Scheduler 1.0 interface, which is still available in Vista and is compatible with Windows XP, Windows Server 2003 and Windows 2000.
注意:自从这个库创建以来,微软已经为Windows Vista引入了一个新的任务调度器(任务调度器2.0)。这个库是任务调度器1.0接口的包装器,它在Vista中仍然可用,与Windows XP、Windows Server 2003和Windows 2000兼容。
http://www.codeproject.com/KB/cs/tsnewlib.aspx
http://www.codeproject.com/KB/cs/tsnewlib.aspx