Your user interface is not updated because all work is done in the user interface thread. Your challenge:
this.BeginInvoke((MethodInvoker)delegate() {update.Action.Run(); })
says update.Action.Run () is called in the thread that created "this" (your form), which is the user interface thread.
Application.DoEvents()
will really give the user interface thread the ability to redraw the screen, but I will be tempted to create a new delegate and call BeginInvoke.
This will execute the update.Action.Run () function in a separate thread allocated from the thread pool. You can then continue to check IAsyncResult until the update is complete, requesting the update object to execute it after each check (because you cannot update the current progress bar / UI), and then call Application.DoEvents ().
You will also need to call EndInvoke (), otherwise you may lose resources
I will also be tempted to put a cancel button in the progress dialog and add a timeout, otherwise if the update gets stuck (or takes too long), then your application will be blocked forever.
source share