BeginInvoke
is asyncrhonous. This means that it queues the action to take place in the UI thread and then continues on with its business. Queueing up 100,000 actions in the UI thread doesn't actually take long at all. It in fact takes quite a lot less time than actually executing each of those actions. This means that the queue ends up being flooded with all of these requests to update the text. When a new request is added, say, a request to repaint the form to display the new value, or respond to a mouse click event on the form, it is placed at the end of the queue, after those many thousands of other requests.
If you use Invoke
, instead of BeginInvoke
, then the background worker won't move on to queue the next item until the previous item has finished running in the UI thread, keeping it from getting ahead of the UI thread and flooding the queue. This means that any other UI events, such as the events to actually repaint the screen, don't have more than at most one item in the queue to wait behind.