Search code examples
c#.netmultithreadingtimerbackgroundworker

Any need for BackgroundWorker if using System.Threading.Timer?


If I need a task to run in the background once per hour, can I just use a Timer object which apparently will use a separate thread: http://msdn.microsoft.com/en-us/library/zdzx8wx8.aspx ?

It would seem from this that there is no need to use a BackgroundWorker for my purposes. Is this correct?


Solution

  • That very much depends on what your task is. The BackgroundWorker component will give you several additional features over and above the Timer, including cancellation support, progress reporting and so on. However, if you just want to kick something off every hour and don't require anything further, then the Timer is a very lightweight choice.

    Have you researched using the Task Scheduler as another option? There's a neat wrapper here: http://taskscheduler.codeplex.com/