Had some nice thread code that presented windows to user for interaction. This was kind of OK (no it was not, but it worked…) in Real Studio.
I’m currently moving some projects to Xojo and Xojo prohibits doing user interaction from threads - which is fine.
The problem for me now was how do I present a dialog for the user without needing to rewrite a lot of my code?
I stumbled upon CallMethodLaterMBS by Monkeybread Software which made my life rather easy:
DoManualRun //A method in my thread that presents a dialog window.
Why don’t you use CallMethodOnMainThread if you are using a delay of 0 seconds anyway?
And I fully agree, these methods are very very helpful. The simplify the spaghetti of threads and timers.
And I wonder why there is a need for such a plugin function at all. This should be available as native Xojo call!
Is there a difference to xojo.core.timer.CallLater(afterMsec As Integer, method As Xojo.Core.Timer.CallNoParams) ?
probably not. But the plugin function is older and still works in Real Studio projects.
I have been wondering what this CallLater means… CallMethodOnMainThread is so much clearer.
CallMethodOnMainThread is same as CallLater with 0 time.
For those without MBS and what CallLater functionality in xojo versions that don’t support it, I have a free open source class here:
What do these things actually do?
I did a search around and while I can see people saying its great and discussing parameters, the practical usage has passed me by.
What problem does this solve, for example?
You can’t edit GUI in a thread.
SO all this methods take a method call with parameters and store those, execute a timer and on main thread invoke the method.
so you call this while inside a thread,
and the ui is updated safely in the main thread by code in the timer ‘event’?
Is this eventually the same as using a timer?
It is using timer… just one you don’t have to worry about keeping a reference for.
OK, that can come in handy.