start a timer from different thread in c#

后端 未结 4 1779
挽巷
挽巷 2020-12-16 15:37

Hi i have stepped into some problem related to timer. hope somebody can help..

  1. I have a windows form containing a button
  2. when i click on that button i
4条回答
  •  盖世英雄少女心
    2020-12-16 16:00

    System.Windows.Forms.Timer works in a single-threaded application.

    Check this link:

    • http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx

    Remarks says:

    A Timer is used to raise an event at user-defined intervals. This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread.

    Read more "Remarks" section and you'll find that Microsoft recommends that you use this timer synchronizing it with the UI thread.

提交回复
热议问题