Hello everyone,
What is the most convenient way to check whether elapsed time from some time point to another time point is larger than 2 seconds?
Currently, I am using TimeSpan, and I am using stupid method to check hour/minute/second one by one to decide. Are there any quick way to check?
thanks in advance,
George
Bechir BejaouiPosted Apr 12, 2008, 11:07 AM
static int counter = 0;
static bool b = false;
myTimer.Tick+=new EventHandler(myTimer_Tick);
myTimer.Interval = 1000;
myTimer.Start();
while (b == false)
{
// implement your code that corresond to the time not elapsed yet situation
if(b==true)
{
// implement your code that corresond to the time already elapsed situation
break;
}
}
//implement this event handler method like this
static void myTimer_Tick(Object sender, EventArgs e)
{
// Stop the timer
myTimer.Stop();
/* Here we chose 2 seconds or a little more to be in timeout situation */
if (counter < 2)
{
// Enable the counter
myTimer.Enabled = true;
// Increment the counter
counter++;
}
// The condition related to witch the Spalsh form will be disposed
if (counter == 2) b = true;
}