SDF 2.1 Preview: Get LIT!

SDF 2.1 Preview – Get LIT


Ever have a business scenario where you want your application to perform some task on a periodic basis but the period will be very long – maybe days, weeks or even months?  You want it to occur if the device is asleep or aware at the time?  Well we’ve got a new SDF class that’s designed for this: the LargeIntervalTimer (or LIT).



Let’s look at a simple scenario.  Let’s say I’m writing a custom calendar.  I want to set up a recurring meeting.  Well let’s say the first meeting will be tomorrow at the same time as it is now (for simplicity) and then every 7 days after that.  We want the device to do something on that period (presumably make a noise, vibrate or whatever. 


The LIT is specially designed for this type of scenario.  The code to do achieve that scenario would look like this:


// we want the first timer event o happen 1 day from now
m_lit.FirstEventTime = DateTime.Now.AddDays(1);

// after the first event, we want it to fire every 7 days
m_lit.Interval = new TimeSpan(7, 0, 0, 0);

// we want it to be recurring
m_lit.OneShot = false;

// wire up a handler
m_lit.Tick += new EventHandler(LIT_Tick);

// start the timer
m_lit.Enabled = true;


That’s it.  No P/Invokes.  No ugly Notifications, threads, events or whatever.  We’ve swept all that ugliness under the rug for you so all you need to do it implement your app.