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.

One thought on “SDF 2.1 Preview: Get LIT!”

  1. I’m having trouble getting the LIT working in VB.Net Everything seems OK except Tick event doesn’t fire.

    Below are some of the key lines, Any ideas of what might be wrong?

    In Declarations…
    Private WithEvents notifytimer As New LargeIntervalTimer

    setup notifytimer….
    AddHandler notifytimer.Tick, AddressOf notifyUser
    notifytimer.enabled = true

    Private Sub notifyUser(ByVal sender As Object, ByVal e As EventArgs)
    Debug.WriteLine("Timer Ticked at " & Now.ToShortTimeString)
    End Sub


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s