I see two options
- Windows Task Scheduler with a repeating task that executes your application
- Windows Service that polls the date at [some_time] every day.
In the first option, you won't need a timer as windows is managing the clock polling for you. In the second option, a timer is appropriate. Working out how long to make it is up to you!
Edit - some insanely trivial code examples
Option 1. call into the windows task scheduler executable and set up your task using command line ->
Schedule task in Windows Task Scheduler C#
Type schtasks /CREATE /?
at a command prompt to get you started!
Option 2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimeToTarget
{
class Program
{
static TimeSpan m_TimeToTarget = default(TimeSpan);
static void Main(string[] args)
{
//maybe you can load this from file or take it from the commandline as commented below
//string cmd = Environment.GetCommandLineArgs();
DateTime now = DateTime.Now;
DateTime target = new DateTime(now.Year, 11, 15); //November 15th. Use todays year.
//we want to set a timer for the next occurance of Nov 15th.
if (DateTime.Now > target)
{
//increment the year because today is after Nov 15th but before new year.
target = new DateTime(now.Year, 11, 15).AddYears(1);
}
m_TimeToTarget = target.Subtract(now);
//kick off a timer to wait for the event
SetTimer(m_TimeToTarget);
Console.ReadLine(); //console needs to continue running to keep the process alive as timer runs in background thread
}
private static void SetTimer(TimeSpan timeToTarget)
{
System.Threading.Timer t = new System.Threading.Timer(DoWork, null, Convert.ToInt32(timeToTarget.TotalMilliseconds),
System.Threading.Timeout.Infinite); //dont repeat, we want the time to end when it start our work
}
private static void DoWork(object state)
{
//Do you work here!
//restart the time
SetTimer(m_TimeToTarget);
}
}
}