Closed IlSocio closed 9 years ago
Hi @IlSocio
Thanks for this - you are right. The get on Shared DOES need to be run on the UI thread the first time.
So: quick fix is to do that the first time (just PRogressHUD.Shared;
should do it?) on the UI thread, then use as normal. I'll fix this shortly and put it into the component store.
Thanks!
It would fix the issue for sure, but, actually the "issue" exists just in terms of how BTProgressHUD control has been designed, I'm referring to the fact that this control takes care of switching to the main ui thread by its own in it's implementation.
Imho, a much better approach would be to remove all the InvokeOnMainThread / RunOnUiThread calls from BTProgressHUD and let the developers to take care of switching to the main ui thread when using BTProgressHUD control, like we already do when using any other gui controls provided by the framework. Doing it inside BTProgressHUD, kills the performances and it's not needed, because in any case, we will have to switch on the main thread by our own just to update a simple label...
Thanks. Mostly fixed (the exception is thrown anyway) in https://github.com/nicwise/BTProgressHUD/commit/b46bd9e6a2658cb0668786279d33c629ed6aad6a
I just got the exception below:
And it seems to be caused by this line of code, which tries to get the MainScreen instance from a background thread: https://github.com/nicwise/BTProgressHUD/blob/master/BTProgressHUD/ProgressHUD.cs#L189
Despite it could be easily fixed by wrapping it around an InvokeOnMainThread(), IMHO, ALL the InvokeOnMainThread() should be definitely removed from this component and replaced with just a UIApplication.EnsureUIThread() check... as suggested here: http://tirania.org/monomac/archive/2012/Sep-10.html it would improve both consistency and efficiency.
When working with gui components, developers are already used to call the InvokeOnMainThread() when they're working in a background thread. In this way, with a single InvokeOnMainThread() call we can perfom all the gui related operations on all different gui component... eg. show the progressdialog, update a label, populate a combo...
While, delegating the call of the InvokeOnMainThread() to each gui component, would be overkill due to the multiple switches from background thread and main thread...