Time outs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lou

    #1

    Time outs

    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",ma rkTime,Now).2 then exit do

    Thanks
    -Lou


  • Jerry Negrelli

    #2
    Time outs

    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,Date Time.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
    [color=blue]
    >-----Original Message-----
    >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",ma rkTime,Now).2 then exit do
    >
    >Thanks
    >-Lou
    >
    >
    >.
    >[/color]

    Comment

    • Lou

      #3
      Re: Time outs

      Can you show an example?

      "Jerry Negrelli" <jerry.negrelli @removethispart datascientific. com> wrote in
      message news:004101c3c0 d6$196a3130$a40 1280a@phx.gbl.. .[color=blue]
      > 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,Date Time.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
      >[color=green]
      > >-----Original Message-----
      > >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",ma rkTime,Now).2 then exit do
      > >
      > >Thanks
      > >-Lou
      > >
      > >
      > >.
      > >[/color][/color]


      Comment

      • Jerry Negrelli

        #4
        Re: Time outs

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

        using System.Threadin g;

        //...code omitted...
        public void ExampleMethod1( ){
        Thread myEvilThread = new Thread(new ThreadStart
        (ExampleMethod2 ));
        myEvilThread.St art();
        System.Threadin g.Thread.Sleep( 2000); //pause 2 seconds
        myEvilThread.Ab ort();
        }

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


        JER
        [color=blue]
        >-----Original Message-----
        >Can you show an example?
        >
        >"Jerry Negrelli"[/color]
        <jerry.negrelli @removethispart datascientific. com> wrote in[color=blue]
        >message news:004101c3c0 d6$196a3130$a40 1280a@phx.gbl.. .[color=green]
        >> 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,Date Time.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[/color][/color]
        elapses.[color=blue][color=green]
        >>
        >>
        >> JER
        >>[color=darkred]
        >> >-----Original Message-----
        >> >How can i do a time out based on seconds or[/color][/color][/color]
        milliseconds.[color=blue][color=green][color=darkred]
        >> >I need to exit loops based on a time value.
        >> >
        >> >The VB6 equiv is:
        >> >
        >> >Dim markTime As Date
        >> >marktime=Now
        >> >If DateDiff("s",ma rkTime,Now).2 then exit do
        >> >
        >> >Thanks
        >> >-Lou
        >> >
        >> >
        >> >.
        >> >[/color][/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...