timer problem

I've a timer (interval = 1000) in my app.
When the timer is working parallelly a big loop is also working. but I found out untile this loop not finished the timer won't work.
How can I force the timer to alwasy work every second


Answer this question

timer problem

  • DonovanH

    In your big other loop, try calling Application.DoEvents() for every iteration. 

    Timers are based on (I think) windows messages - and so, they need a message loop to be running to process these windows messages.  When you have this big loop, your thread is spending all the time on this big loop and the message loop never gets time to process the messages in the queue.  Calling Application.DoEvents() will forces the message loop to process the messsages in the queue.

  • KasiSunkara

    Usually in that case, you would create a new thread and run the DB Query in the new thread.  It's generally a good idea to keep the UI thread separate from the worker thread.
  • ChindhiChor

    I found this article about using threads in c# (http://abstractvb.com/code.asp A=1028) but when I tried to compile this sample the compiler return this error:
    The type or namespace name 'CallBack' could not be found (are you missing a using directive or an assembly reference )

  • dechainelafureurnico

    Would you please explain what's the running message loop
  • chainding

    Any other solution plz

  • Thomas Pagel

    thanks about your explanation but could you make an example of using such threads
  • Vijay0638

    Thanks for your great solution.
    But sometimes we can't do this. e.x. when We orfer an OleDbCommand to execute a query.
    Untile OleDbCommand is running this query we can't call Application.DoEvents() but we need timer to works on it's time.
    What we can do in this case

  • cobaltsoft

    Timers need a running message loop.

  • Damir Tomicic

    This is not possible when the OleDbCommand is running in thread were the timers are expected. You have to run the SQL query in a second thread!

  • timer problem