Alternative to Timer

人盡茶涼 提交于 2020-01-06 13:51:12

问题


I'm developing a c# winform application which is based on third party web API's for trading purpose. It deals with real time data coming from internet like currency rates but I'm using 8 timer in my winform to retrieve different data, application gets non-responding because of timers,

what can i do to make this application work fast and smooth?


回答1:


You might want to look into the System.Threading.Timer instead: Timer Class

System.Threading.Timer, which executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed. Like the System.Timers.Timer class, this class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.

This link has a nice table of comparison between the different timer classes at the bottom:

Comparing the Timer Classes in the .NET Framework Class Library




回答2:


Use threading. Timers (at least the ones you seem to be using) are executed in the GUI's thread. Use BackgroundWorkers (or other threading methods) instead to decouple background tasks from the GUI.



来源:https://stackoverflow.com/questions/26672216/alternative-to-timer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!