Thread

Hi…
Am at learning stage in Xojo… Help me out below case;

How to pass the parameter from Window to Thread?

I would create a new method in the thread called Constructor and add your parameters to that method.
Then pass the parameters when declaring a new thread:
Dim th as new yourThread(param1, param2)

In the Constructor method you can pass the parameters to properties in the thread. That’s one way of doing it :slight_smile:

Does your thread live in the window? Then the above method won’t work.

In which case you could Subclass Thread and add a second Run method which takes a parameter.

If the thread is embedded in the window at design time, it has access to all the window’s properties already. Use the above for better encapsulation, but if you just need something dirty that works, you could embed the thread.

Thanks for response… I didn’t get clear picture on this.

My objective is , I have to receive the Data from one UDP socket ( Another system) & I need to pass this data to “Thread”.
In this Thread i have written the code for Send reply message to that UDP Address (Incoming UDP Address)

For this , i was not able to pass the UDP data to Thread as well pass the Reply message to UDP Address.

" Thread was not live in Window"…

If there is a one-to-one relationship between socket and thread, then use Greg’s idea and create a second Run event. Pass it a reference to the socket. Store that reference and call the normal Run method. Create a subclass of Thread and add

sub Run(sock as UDPSocket)
    mSock = sock
    Run
end sub

Use mSock (or whatever you want to call the property) in the Run event of the thread to send a reply.

Is there any example for above case.