Time outs

  • Thread starter Thread starter Lou
  • Start date Start date
L

Lou

How can i do a time out based on seconds or milliseconds.
I need to exit loops based on a time value.

The VB6 equiv is:

Dim markTime As Date
marktime=Now
If DateDiff("s",markTime,Now).2 then exit do

Thanks
-Lou
 
You can do it the same way, if that's how it has to be
done:

DateTime markTime = DateTime.Now;
do{
if(DateDiff("s",markTimer,DateTime.Now) >= 2){
break;
}

// some code...

} while(...);


If you want your timeout to be EXACT, I'd use threading
and abort your thread when a specific time period elapses.


JER
 
Can you show an example?

Jerry Negrelli said:
You can do it the same way, if that's how it has to be
done:

DateTime markTime = DateTime.Now;
do{
if(DateDiff("s",markTimer,DateTime.Now) >= 2){
break;
}

// some code...

} while(...);


If you want your timeout to be EXACT, I'd use threading
and abort your thread when a specific time period elapses.


JER
 
Hmm, off the top of my head this is one way to do that;
there are many ways...

using System.Threading;

//...code omitted...
public void ExampleMethod1(){
Thread myEvilThread = new Thread(new ThreadStart
(ExampleMethod2));
myEvilThread.Start();
System.Threading.Thread.Sleep(2000); //pause 2 seconds
myEvilThread.Abort();
}

public void ExampleMethod2(){
//...do some stuff
}


JER
 
Back
Top