2012-01-18, 06:45 PM
If I want to update the UI from a background thread, what's the best way of doing that?
I came across this code on the web, but it doesn't work because I think it's really designed for windows forms:
I know this sort of stuff causes problems in Java if not done correctly, where the solution is a simple SwingUtilities.invoke... method similar to the above, and sub has mentioned in the past it would cause problems with NPVR too. I've certainly seen (rare) cases in the System plugin where the text suddenly renders nowhere near its location according to the skin (usually way out on the x-axis). I figured it might be down to the background threading I use, but I've also seen that problem once - and just the once - with the now/next popup too.
Regardless of that, I'd like to know I was doing it properly anyway.
Iain
I came across this code on the web, but it doesn't work because I think it's really designed for windows forms:
Code:
this.Invoke((MethodInvoker)delegate
{
uiStatic.Args = some hashtable that's been updated in the thread;
});
I know this sort of stuff causes problems in Java if not done correctly, where the solution is a simple SwingUtilities.invoke... method similar to the above, and sub has mentioned in the past it would cause problems with NPVR too. I've certainly seen (rare) cases in the System plugin where the text suddenly renders nowhere near its location according to the skin (usually way out on the x-axis). I figured it might be down to the background threading I use, but I've also seen that problem once - and just the once - with the now/next popup too.
Regardless of that, I'd like to know I was doing it properly anyway.
Iain