开发者

.Net long-running scheduled code execution

I am working on a couple of projects now where I really wish there was some sort of component that I could specify a time and date, and then execute some sort of method.

DateTime date = new DateTime(x,x,x,x,x,x);
ScheduledMethod sMethod = new ScheduledMethod(date, [method delegate of some sort]);

\\at the specified date, sMethod invokes [method delegate of some sort]

I know that I can do this with Windows Workflow Foundation as a long running process, which is good for certain things, but are there any alternatives? Workflow is not exactly straight forward with the details, and it would be nice to be able to deploy something more simple for light weight tasks. An example would be a method that checks a network folder once a day and deletes any files that are more than 开发者_运维知识库30 days old. I realize that this may be pie in the sky dreaming, but this would be extremely useful for automating certain mundane maintinence tasks (scheduled sql operations, file system cleansing, routine email sending, etc.). It does not necessarily have to be .Net, but that is where I am coming from. Any ideas?


try windows task scheduler. write a program in C# that performs the desired task and then schedule it in task scheduler to run at specified intervals. for things like deleting files from a folder this works very well.


You could deploy a Windows Service or a Windows Scheduled Task.

Also, see this SO question.


I typically make a console application for the task and configure it as a scheduled task in Windows. That usually works out perfectly fine. Add some decent logging to the application so you can troubleshoot in a simple manner if anything goes wrong.


Microsoft has Task Scheduler interface for unmanaged code http://msdn.microsoft.com/en-us/library/aa383614(v=VS.85).aspx. However if you need managed library you can use wrapper around Microsoft Task Scheduler http://www.codeproject.com/KB/cs/tsnewlib.aspx or enterprise job scheduler for .NET QuartzNet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜