Hi!
I have some code that adds buttons in a toolbar dynamically. This code runs on RunWorkerCompleted of a background worker (this is because the buttons I am about to add refer to data loaded from a database, so I want to use a background thread). Code is executed without exception but buttons are not shown.
If I temporarily cut and paste the same code so that it is out of the background work context it runs again and the buttons are show properly.
What's going on?
You can only update the UI on the main thead. Take a look at the following articles:
http://www.bokebb.com/dev/english/1960/posts/196053863.shtml
http://weblogs.asp.net/justin_rogers/articles/126345.aspx
But RunWorkerCompleted event does run on the UI thread. I forgot mention that I tried already to do this using Invoke in order to ensure that code runs on the UI thread but I get the same result.
In any case, even if one does the mistake to run the code on a thread other than the UI thread I would expect to get an exception. However I don't.
There are 2 issues here: