Determine if my code is running in a thread

I have some code that might run on the main thread or might be called from a background thread. If the latter, I don’t want to display any UI.

The docs state that querying Thread.Current will return nil if called outside of a thread. So is it safe enough to write: If Thread.Current = Nil Then (show some UI) ?

Yes.

2 Likes

Thank you Kem. :slight_smile:

Be aware, Thread.Current used to have this note in the documentation:

Notes

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’m not sure if Xojo changed their mind about this, or if it’s another effect of documentation-gate.