Instead of having one task to perform all these half-dozen functions (login, etc.), each function performs a separate task. Then you can create a priority queue ordered by time. When you want to run one of these meta tasks, you put your first function in the queue along with status data (i.e. URL, user ID, password, etc.).
As each function completes, it pauses the next function. Therefore, if the first two functions are login and get_data, you will have:
queue login with state data to execute at DateTime.Now When login is finished, it queues get_data with the state data and DateTime.Now + 5 seconds (or whatever time)
When the last function is executed, it sends the results somewhere.
Then you can set a timer that will poll the queue 10 times per second (or the timer time of the next tick will be updated whenever something is added to the queue). It can run individual tasks as needed.
The new Async CTP may already have this thing: "complete the task on time." It might be worth exploring it.
Regarding progress in reports, each function can report progress at startup (i.e., "logging in" ... "waiting 5 seconds to receive data" ... "receiving data", etc.) . If you want, you can force the timer to scroll through the priority queue periodically and let you know when specific tasks will be performed. Although this may be redundant.
And what you heard is correct: Thread.Sleep is an exceptionally bad idea, especially when you work with thread pool threads.
Jim mischel
source share