Timer Control - No Longer Asynchronous?

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

    #1

    Timer Control - No Longer Asynchronous?

    Hi There!

    I'm using Timer control to record how long my application perform certain
    tasks.

    However, apparently Timer control is not doing its' job (i.e. Not firing
    Tick event) while my application is busy. So even if my application took 2
    mins, the label that is used to show the number of seconds elapsed will
    still say "2 seconds".

    While the application is not busy, I enabled the Timer and the second count
    increases normally every second.

    Is this means Timer control in VB.NET is not Asynchronous (like VB6 Timer
    control) ? Or am I missing something? Please help!!!

    Thanks in advance!!!

    David



  • Imran Koradia

    #2
    Re: Timer Control - No Longer Asynchronous?

    The System.Windows. Forms.Timer runs on the same thread as the application.
    So if your application is carrying out some processor-intensive task, the
    timer ticks are not going to be fired since the thread is busy doing your
    task. Instead, use the System.Timers.T imer (which runs on a seperate thread
    than the application) and write your code in the Elapsed event of the timer.

    hope that helps..
    Imran.

    "David" <no-email@mailingsp am.com> wrote in message
    news:eSkn%23uLn EHA.132@TK2MSFT NGP09.phx.gbl.. .[color=blue]
    > Hi There!
    >
    > I'm using Timer control to record how long my application perform certain
    > tasks.
    >
    > However, apparently Timer control is not doing its' job (i.e. Not firing
    > Tick event) while my application is busy. So even if my application took 2
    > mins, the label that is used to show the number of seconds elapsed will
    > still say "2 seconds".
    >
    > While the application is not busy, I enabled the Timer and the second[/color]
    count[color=blue]
    > increases normally every second.
    >
    > Is this means Timer control in VB.NET is not Asynchronous (like VB6 Timer
    > control) ? Or am I missing something? Please help!!!
    >
    > Thanks in advance!!!
    >
    > David
    >
    >
    >[/color]


    Comment

    • Ken Halter

      #3
      Re: Timer Control - No Longer Asynchronous?

      David wrote:[color=blue]
      > Is this means Timer control in VB.NET is not Asynchronous (like VB6 Timer
      > control) ? Or am I missing something? Please help!!![/color]

      The VB6 Timer control was never asynchronous. It worked exactly the same
      as every other event driven component. When an event fires, the programs
      instruction pointer is saved and then moved to the top of the event
      handler procedure and will be returned to the saved address when the End
      Sub runs in that event handler procedure.

      Private Sub ABC()
      1 code here
      2 code here
      3 code here
      'timer event fires after running line 3
      'code in timer's event handler runs
      'returns to line 4 after the End Sub in the timer event
      4 code here
      5 code here
      6 code here
      End Sub

      Private Sub Timer1_Timer()
      'This entire procedure runs before
      'returning to line 4 above
      'it will never return until the line below runs
      End Sub



      --
      Ken Halter - MS-MVP-VB - http://www.vbsight.com
      Please keep all discussions in the groups..

      Comment

      • Hal Rosser

        #4
        Re: Timer Control - No Longer Asynchronous?

        > I'm using Timer control to record how long my application perform certain[color=blue]
        > tasks.
        >
        > However, apparently Timer control is not doing its' job (i.e. Not firing
        > Tick event) while my application is busy. So even if my application took 2
        > mins, the label that is used to show the number of seconds elapsed will
        > still say "2 seconds".
        >[/color]

        Maybe you should use dateTime instead of a timer control.
        COmpare the time before the task to the time after the task.



        ---
        Outgoing mail is certified Virus Free.
        Checked by AVG anti-virus system (http://www.grisoft.com).
        Version: 6.0.754 / Virus Database: 504 - Release Date: 9/6/2004


        Comment

        Working...