Called from Main Thread or from Thread

  1. 2 months ago

    Bob K

    Feb 12 Pre-Release Testers, Xojo Pro Kansas City

    I have a method that can be called from a thread or not (I didn't program this part). Is there a simple way to determine if the method is being called from the main thread or from within a thread? I have to do this because if I'm in the main thread I display a message, but if I'm within a thread I just want to log the error.

    Short of rewriting a lot of code to handle this I'm wondering if there's a less intrusive way of checking for this.

  2. Tim P

    Feb 12 Pre-Release Testers Austin, TX

    App.CurrentThread will be nil if on the main thread.

    if App.CurrentThread = nil then
      MsgBox("Hello, world!")
    else
      // Thread safe error handling
    end
  3. Bob K

    Feb 12 Pre-Release Testers, Xojo Pro Kansas City

    Ug. I hate it when I knew the answer and forgot that I knew it. Thanks.

  4. Kem T

    Feb 12 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    Similarly, I hate when @Bob K knows the answer and I forgot that Bob knew it. (This applies to most things.)

  5. brian f

    Feb 12 Pre-Release Testers, Xojo Pro Chilly California

    I know Kem was itching to reply with a regex solution because he has not spoken Klingon in 24 hrs. :P

  6. Tim J

    Feb 12 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    @Kem T Similarly, I hate when @Bob K knows the answer and I forgot that Bob knew it. (This applies to most things.)

    I'll bet there's a RegEx for that! :P

  7. Kem T

    Feb 12 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    I'm good at other things too, you know, like... like... other things!

  8. Daniel T

    Feb 12 Pre-Release Testers, Xojo Pro

    @Tim J I'll bet there's a RegEx for that! :P

    If there is a RegEx solution for it, Kem is the guy who can write it.

or Sign Up to reply!