How to continue using an application whilst waiting for a function to execute repetitively on a fixed interval

Hi

i am ruuning the following extract of coding from visual basic 2005:

__________________________________________

Dim start, finish As Double

Do While DateTime.Now.Hour < 17

start = Microsoft.VisualBasic.DateAndTime.Timer

' Set end time for 30-second duration.

finish = start + 30.0

Do While Microsoft.VisualBasic.DateAndTime.Timer < finish

' Wait a while before doing next action

Loop

call_a_function() ' Go off and do something then come back

Loop

______________________________________________________

While the program falls into the "wait state" (2nd do while loop) the program stops me accessing anything else on the active form, like using a drop down list or changing a tab page. It would seem the program halts in the wait state stopping you from doing anything else.

I am running this on a windows mobile 2005, so while it is in the "wait state" i want to switch to another app or do something in the current app but can't.

I want to call a function every 30 seconds within specified hours, but want to carry on using other area of the app or even use a different app.

Is there a way this can be achieved

regards

Raja



Answer this question

How to continue using an application whilst waiting for a function to execute repetitively on a fixed interval

  • DarrellMerryweather

    Michael

    thank you for your patience in breaking down the "How to...". The code works perfectly.

    regards

    Raja


  • Tom from cener.co.uk

    Instead of using loop you should use a Windows Timer instead.

    Drag a Windows Forms Timer to the form and set its interval to 30 seconds.
    Within the timer Tick event handler implement your time dependant logic.

    Hope this helps.
    Michael



  • MagedSalah

    Ok, here are some step by step instruction which should help.

    First, drag a Timer component from the Toolbox onto the form (this can be found Device Component Tab)
    You should now see a Timer1 icon in the bottom area of the form designer.
    Select the Timer and set the Properties Enabled to True and Interval to 30000

    then add the following method to the Forms code file (Form1.vb)
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If DateTime.Now.Hour < 17
    Then
    call_a_function()
    ' Go off and do something then come back
    End
    If
    End Sub

    Michael



  • Eric SVM

    Michael

    thank ou for your response. A total novice here with VB. Would appreciate any example code on how to implement your suggestion. I understand doing the way you explain would leave the processor to do other tasks freely

    ( you loose me when you talk about.....Within the timer Tick event handler implement your time dependant logic.)

    thanks

    Raja


  • How to continue using an application whilst waiting for a function to execute repetitively on a fixed interval