I’m developing a chat application. For getting frequetly comming request,messages and zone request I’m using one timer and call all methods on timer.now. The problem is that when ever I click on any control in the application this gives me a late response due to the timer running. It first hangs until it completes the timer code then control click event is fire.
So, any help on how to handle this is appreciated, I also tried threading but this didn’t help.
Please give me any idea if u have.
Thanks.
Use System.Timers.Timer or System.Threading.Timer instead of the
Windows.Windows.Forms.Timer, and inside theElapcedevent handler whenever you call methods or properties on UI controls usecontrol.InvokeRequiredandcontrol.Invoke.the problem with the form timer is that it perform the action on UI thread, From msdn:
Edit: Here is example using
System.Timers.Timer:Edit2: Another thing to notice that depending on execution time on the elapsed event handler, if the time required to execute the code on it is larger than 1 second then I suggest you to set
_chatTimer.AutoResetto false and only start the timer after the previous elapsed event is finished. for example check this.