Using sleep time is pointless. In your case, you should create a thread from the very beginning (not by click) and keep it sleeping (actually, in wait state not using any CPU time until awaken) using thread synchronization primitives, like
System.Threading.EventWaitHandle
. More advanced use would be using a generic blocking queue with elements each representing a "task" for a thread, see my Tips/Trick article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
Best way to create a thread is using wrapper, here is how:
How to pass ref parameter to the thread[
^].
For a general design schema, see my Answers to similar Questions:
Control.Invoke() vs. Control.BeginInvoke()[
^]
Problem with Treeview Scanner And MD5[
^]
Multple clients from same port Number[
^] (this one is for TCP, but many recommendations are still valid for your case)
How to get a keydown event to operate on a different thread in vb.net[
^]
—SA