2

I need to write a program in .NET which runs every few hours and does some task. It does not require user interaction but it needs a configuration file like App.config where I can put that configuration information.

So should I write console program in C# ( like php or perl script) and schedule it in task manager ( like crontab) or write a Windows Service or something else?

4

3 回答 3

2

If you want scheduling capabilities and that schedule needs to be very configurable, a windows scheduled task does that pretty well. You would write that as a console app.

However, I would suggest a service for most things. Here is a great tutorial that talks about how to create windows services. Its much easier than you think.

http://www.switchonthecode.com/tutorials/creating-a-simple-windows-service-in-csharp

于 2012-12-19T22:58:34.047 回答
1

My suggestion would be to go for the console app and use the task manager.

  1. It saves you from having to implement a custom timer
  2. It gives you elaborate control over timing
  3. It saves you from having to implement an UI
  4. It gives you automation options, like piping in- and output at the command line
于 2012-12-19T22:59:07.433 回答
1

Depending on the complexity of your task the best option would be to create an application which can be run via a task scheduler. If you need to run something every few hours a windows service would also work, but remember if you create a windows service then you will have to use a timer control within your application which might hang up without giving any clues. There are lots of examples for both the concepts and instead of using windows service you can use Window Communication Foundation (WCF).

于 2012-12-19T23:01:39.477 回答