Resetting timers

You are testing the Timer to see if it is null but never setting it back to null after it expires or you cancel it. So after you create your first Timer if(OfficeLightTimer == null) will always evaluate to false.

So set the last line of your Timer body to set OfficeLightTimer to null and be sure to set OfficeLightTimer to null after you cancel it.

The second problem is that you are missing the else in your second Rule so you create the Timer and then immediately cancel it.

I highly recommend the Expire binding, as Thomas suggested. Design Pattern: Expire Binding Based Timers will show you have to do it. It ends up making the code much simpler to write and understand. No more book keeping.

Not wrong, both are valid syntax.

1 Like