24 hr time handling

Hi,
I wonder if you have any tips on this subject;
My app will be running in the background and perform tasks on certain times and also react differently on certain events depending on the time and date.

For example, if a certain button can maximum be allowed to be pushed 15 times a day, how would I do And say after being pushed three times, it cannot be pushed for the next 30 minutes and then I could push it three times again before it gets disabled for a while. Thankful for tips.





Answer this question

24 hr time handling

  • 87jerome

    There are probably a number of different ways of going about this, but you'll probably want to make use of System.Windows.Forms.Timer


  • Rgranada

    And if you want to store this information to persist it across restarts - a handy way to store DateTime value is to use ToFileTime() method to convert to long (and FromFileTime to get back).

  • Deepa7476

    indeed, you would need the Timer class firstly to run the processes needed to be ran throughout the timeframe of the application being ran.

    Secondly you probably want to store the DateTime of the button being pushed on the button click event. So if they press the button, they would check the last time the button was pressed, compare the current time and see if it has been 30 minutes or more before they can execute the function of the button.

    you could also have a global variable, something like "NumberOfTimesPushedToday", and increment 1 to it on the push of the button. now, when the button is pushed, check to see how many times its been pushed, if its more than the specified number of times then don't execute whatever function if it you want.

    The variable would be reset if the current DateTime is a new day/ 00:00:00 time.



  • 24 hr time handling