Just wondering.
you should not need it since there is me.Sleep()
@Christian_Schmitz I knew someone would say that, lol. Yes, I do use sleep for code that’s only in the thread, but I have a routine that can also be called from the main thread and I would prefer not to duplicate it or complicate it with conditional code if I don’t have to.
You could check app.CurrentThread and then do either a sleep or DelayMBS.
Yes. But would still like to know the answer to my question
Also, it looks like app.CurrentThread has been deprecated and possibly replaced by Thread.Current. In any case it’d be messy, as I call the method from various different threads, and also, per the docs:
" While this property is currently Nil when accessed from the main thread, do NOT rely on this behavior as it may not be the case in future releases."
I have one method where I have to do:
t = Thread.Current
if (t=Nil) then // Allows this to be called from a thread or not
writeLogging (scrbuf, colour)
else
t.UIupdate (28, scrbuf, colour)
end if
.
and I have to be able to call the method from anywhere. I don’t care whether detecting mainthread vs. my thread relies on Nil or not or something else but I do need to be able to tell the difference.
You should ignore this advice, since Xojo has not given us an alternative. I’m usually all for heeding warnings like this and scold people for ignoring them. But I’m this case, Xojo won’t tell us what we should be doing instead. So ignoring the advice is literally the only option.
Perhaps they’ll change it so that thread.current is always non-Nil, and add some other property to thread that we can test for main-thread-ness. Who knows!
One alternative which will guarantee that it will work would be to never upgrade to new releases
Well, if @Christian_Schmitz answers my question in the affirmative, it will be moot I’m using DelayMBS now and it seems to work fine, but I’d like to know there are no hidden issues lurking.
They might, but until they tell us how to heed their advice, it doesn’t matter.
<https://xojo.com/issue/65607> : Docs say not to rely on Thread.current = nil but they don’t say what to use instead
Open since August 2021.
Still if the thread sleeps, it should have the effect, that Xojo switches to another thread and do work there and not come back to your thread until the time is over.
DelayMBS would mean the thread may stay active and run our function, which may yield to other threads, but this may cause more thread switches.
Even if I call it with the second parameter
const DelayDontRBYield = 2 // Don't give Xojo time for other Xojo threads
?
That would block yielding.