Winforms updates with high performance

前端 未结 2 1298
无人共我
无人共我 2020-12-12 03:33

Let me setup this question with some background information, we have a long running process which will be generating data in a Windows Form. So, obviously some form of multi

2条回答
  •  自闭症患者
    2020-12-12 04:15

    There is little point in trying to report progress any faster than the user can keep track of it.

    If your background thread is posting messages faster than the GUI can process them, (and you have all the symtoms of this - poor GUI resonse to user input, DoEvents runaway recursion), you have to throttle the progress updates somehow.

    A common approach is to update the GUI using a main-thread form timer at a rate sufficiently small that the user sees an acceptable progress readout. You may need a mutex or critical section to protect shared data, though that amy not be necessary if the progress value to be monitored is an int/uint.

    An alternative is to strangle the thread by forcing it to block on an event or semaphore until the GUI is idle.

提交回复
热议问题