C# Windows Service using a timer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to write a C# windows service that will scan a specified directory every n minutes, the number of minutes needs to be passed in via an argument for examples directoryscanner.exe /timer:5 , would tell the program to scan the directory every 5 minutes

Therefore my question how do I code my program to do this. I envisage that some sort of timer is required that will raise a method within my program at the specified interval, also how do I read in the argument on the command line.

Many thanks
 
Use the Timer class in System.Threading.Timer. This would be a member variable within your service, which will be created on service startup.

To read the command line, service classes have the following main method signature:

static void Main(string[] args)

where args is a string array representing your command line params.

Cheers
Dan
 
Back
Top