URscript with Thread

Greetings UR Community,
I’ve been developing scripts on a C# app and I run them via Socket throught the port 30003. From what I have tested, I have some questions:
1 - I need to place a thread in this script. For instance, I have this script
def program():
movep()
movep()
global var = 1
movep()
movep()
halt
end

I need a thread like this
thread th = new thread()
if (var == 1)
set_standard_digital_out(1, False) (I set an output to false)
while (get_standard_digital_in(2) == False) (I wait until an input is true)
sleep(0.01)
endwhile
endif

This way the robot does not stop moving while it is waiting for the digital_in(2) becomes True
I don’t know how to do this since I am accustomed only to send a main program without any thread
If I haven’t made myself clear, please let me know

Best regards,
Pedro Monforte

See section 9, as it details how Threads can be created in Script