QUESTION: How can I schedule tasks in a WinForms app? That is either (a) what is the best approach / .NET classes/methods to use of (b) if there is an open source component that does this well which one would be recommended.
BACKGROUND:
- Winforms app (.NET v3.5, C#, VS2008)
- I’m assuming I will run the winforms application always, and just minimise to the system tray when not in use
- Want a simple approach (didn’t want to get into separate service running that UI winforms app talks to etc)
- Want to be able to let the user select how often to schedule the sync (e.g. hourly, daily – pick time, etc)
- Ability to at the times when the scheduler fires to run a chunk of code (assume it could be wrapped as a backgroundworker task for example)
- The application is always running & appears in the system tray
If you don’t want a Windows service then starting the application with windows is an option. You can use the following code to do that.
What did you mean by schedule the sync? Is it a diff service? Then you can use the timer and then store the user settings in an xml file or a DB. If you want a simple storage then you can use My.Settings.
Edit: I think the only way is to check for the date when the app starts and then check the date periodically. Another option is to use the task scheduler programatically. Task Scheduler Managed Wrapper is an open source wrapper which you can try out.