none
Why timer stops when a dialog box is opened?

    Question

  • hello

    I have this code in my MainForm:

    CheckForIllegalCrossThreadCalls = False
    Dim CountTrafficThread As New Threading.Timer(New Threading.TimerCallback( AddressOf CountTraffic), Nothing, 0, 500)


    it works good but, when I call a dialog box from this form, the timer is stopped and counter can not count. If i use a Timer Object from toolbox it work good even after calling dialog box.

    please help me.

    thank you

    Sunday, April 16, 2017 10:25 AM

All replies

  • The Timer runs to the specific time you have set then stops is normal behavior. If you want to trigger the timer again use the Change method. There are several overloads for change as documented on this page.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, April 16, 2017 11:11 AM
    Moderator
  • hello

    I have this code in my MainForm:

    CheckForIllegalCrossThreadCalls = False
    Dim CountTrafficThread As New Threading.Timer(New Threading.TimerCallback( AddressOf CountTraffic), Nothing, 0, 500)


    it works good but, when I call a dialog box from this form, the timer is stopped and counter can not count. If i use a Timer Object from toolbox it work good even after calling dialog box.

    please help me.

    thank you

    CheckForIllegalCrossThreadCalls = False

    Don't use that - ever. It's a leftover that honestly should be removed.

    Are you sure you need a Threading timer rather than a standard timer?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, April 16, 2017 11:15 AM