Users created plugin. Threads.

Hello! I created plugin, there are contained the eternal cycle(this needed for communication with my server).
How can I run this code in other thread? Or you can tell how to get rid of the eternal cycle?

Best regards.