Timer components RRS feed

  • Question

  • am trying to develop certification record system by C#, access database and i want to know about Timer, here is the problem:- when a customer come to our office and register his/her company, the company name will be registered as new on our system, every year the company certificat has to be renewal and to renew our stuff mebers go on site and check wither there working properly or not ..... so i want my system to count starting form the registeration of the company to 12 month and give them some notification;

    can this be done with Timer???

    Thank You for your help. 

    Wednesday, April 2, 2014 6:19 AM


  • Record the date of registration explicitly somewhere.  This is a historical event and doesn't change.

    Compute the expiration date of the registration explicitly by using DateTime.AddYears(1).

    Whenever you want you can compare the  date of expiry with the current date by comparing the two DateTime values (DateTime.Compare)

    DateTime registrationDate = new DateTime( 2013, 04, 2 );
    DateTime expirationDate = registrationDate.AddYears( 1 );
    DateTime currentDate = new DateTime( 2014, 04, 02 ); // Or DateTime.Now.Date
    bool expired = DateTime.Compare( currentDate, expirationDate ) >= 0;

    You can make this check to determine if a registration has expired.

    The nice thing about projecting an expiration date by adding 1 year to the registration date is that you probably intend it to work by choosing the same calendar day of a following year, and that's what AddYears does.  (As opposed to computing the difference in two dates and comparing it to a time span of 1 year).  Not all years have 365 days, for example.  So the length of a year is not constant.  Off-by-one errors like that are likely relevant here.

    I suggest that you write unit tests for whatever you come up with.

    Notice no "timer" is involved here.  Instead I've shown you a way to write an "IsExpired" function based on a given date (or the current date).

    Wednesday, April 2, 2014 5:45 PM