none
Why Thread Timer tick event not hitting when UI doing some other operation? RRS feed

  • Question

  • Hi Team,

    In my application UI, I am updating one of grid through Windows Timer tick every 1 sec.

    It's not working properly when I am doing some other UI operations belongs to another windows forms.

    I added trace for Timer_Tick event and logged in to file. 

    We found there is an missing of log data, when another UI operation going on (Open and closing of another windows form). Timer_Tick not hitting at this time.

    Any suggestions...?



    Ravindra.PC


    • Edited by Ravindra.PC Saturday, October 26, 2013 5:16 AM useful title
    Friday, October 25, 2013 5:43 AM

Answers

All replies

  • The System.Windows.Forms.Timer runs on the UI thread.  The Tick event and Start only occurs when nothing else is executing on the thread.
    Friday, October 25, 2013 8:08 AM
  • Hi John, Thanks for your response.

    So, how to avoid this?

    I want to execute my Ticker thread, even something running on UI.



    Ravindra.PC

    Friday, October 25, 2013 10:47 AM
  • Hi Ravindra,

    I build a project to reproduce your issue, but the result was a little different from you. When I open a form, no matter what in Show or ShowDialog method, the datagridview will been update as expected. When I enter the cell into modify mode, the timer tick event stop updating. You could see my project in http://sdrv.ms/1gXeDPw.

    Please send out the complete source of your project. We only need a simple sample to reproduce the problem. You could remove any confidential information or business logic from it.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 29, 2013 7:28 AM
    Moderator
  • As JohnWein says, the Timer event runs on the UI thread. It sounds like what you would need is multi-threading.

    There are multiple ways of doing this, depending on what you're really trying to achieve (and which version of .NET you're using). One way would be the BackgroundWorker class.

    Tuesday, October 29, 2013 3:34 PM