Passing arguments to a Thread.Run() event

  1. 3 months ago

    Tim J

    Feb 12 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    HI Folks,

    I'm still moving old code from the RS era to Xojo and threads, but I can't find an answer to this one - can we pass arguments to a Thread's Run event. or do we need to set up variables that are then read by the thread. The Developer.Xojo.Com pages are quite sparse on Thread info. In fact, searching for Thread.Run returns nothing.

    I've tried modifying the default Run event with complete failure.

  2. The simple way is setting a global/app/window scope variable and the execute Thread.Run().

    Mod.var  = some_value // or
    App.var  = some_value // or
    Win.var  = some_value
    
    // and then
    thread1.Run()
  3. Jason P

    Feb 12 Xojo Inc http://xojo.com/

    You can't modify the run event - and you don't *call* the Event in either case. You *can* overload the Run *method* in a subclass.

  4. Tim J

    Feb 12 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    Sorry, that should have said "method" instead of "event" above. I have subclassed the thread and tried adding the archives to the exposed Run method, but either I get an error on compile or the argument isn't seen (I'm trying to pass a job-specific array).

    @AsisPatisahusiwa The simple way is setting a global/app/window scope variable and the execute Thread.Run().

    That's what I'm trying to alleviate since I may need to start 10-12 threads, each with its own job information.

  5. Tim P

    Feb 12 Pre-Release Testers, XDC Speakers

    @Tim J That's what I'm trying to alleviate since I may need to start 10-12 threads, each with its own job information.

    Good!

    @Tim J I have subclassed the thread and tried adding the archives to the exposed Run method, but either I get an error on compile or the argument isn't seen (I'm trying to pass a job-specific array).

    I'm not seeing that issue. Here's my test implementation (paste into a .xojo_code file and drag in to the IDE):
    https://pastebin.com/9iFF7bKP

  6. Tim J

    Feb 12 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    Ah - I was creating a new exposed event. I'll re-create it as a Method. Old subclassing habits die hard :)

  7. Jean-Yves P

    Feb 12 Pre-Release Testers, Xojo Pro Europe (France, Besancon)

    @Tim J Ah - I was creating a new exposed event. I'll re-create it as a Method. Old subclassing habits die hard :)

    this is a hard-to-find mistake, as the compiler generates no clear error ...

or Sign Up to reply!