.NET: How to have background thread signal main thread data is available?

后端 未结 7 1969
终归单人心
终归单人心 2021-02-14 04:54

What is the proper technique to have ThreadA signal ThreadB of some event, without having ThreadB sit blocked waiting for an e

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 05:18

    If your "main" thread is the Windows message pump (GUI) thread, then you can poll using a Forms.Timer - tune the timer interval according to how quickly you need to have your GUI thread 'notice' the data from the worker thread.

    Remember to synchronize access to the shared List<> if you are going to use foreach, to avoid CollectionModified exceptions.

    I use this technique for all the market-data-driven GUI updates in a real-time trading application, and it works very well.

提交回复
热议问题