For pausing/resuming thread, use the class
(the behavior of these classes are exactly identical in case you use manual reset). In a thread, you use
. This is a blocking code. If the event is reset (is in nonsignaled
state), it will switch out your downloading thread and put it in the wait state, that is, the thread won't be scheduled back to execution until awaken. So, the wait spends zero CPU time. The thread will be awaken by
or when the same instance
is signaled, which you can do in some different (say, UI) thread, by calling
. This is your mechanism for suspending/resuming your thread.
are unsafe and should be be used.
As to downloading, I would rather advise to use
. Please see:
In contrast to other method, this class will allow you to download a file sequentially, piece by piece, so you can insert
between blocks. More high-level (less direct) methods based on events won't allow you to do so. For a complete code sample, please see my application HttpDownloader:
how to download a file from internet
Please see also my other past answers on the topic:
How to get the data from another site
get specific data from web page