The TaskWait method waits for the specified task to
complete. If the TaskId parameter is omitted, this method will
wait for all active tasks to complete. If a task ID is specified and the
Milliseconds
parameter is non-zero, this method will cause the current working
thread to block until the task completes or the amount of time exceeds
the number of milliseconds specified by the caller. If the
Milliseconds parameter is zero, then this function will poll the
status of the task and return immediately to the caller. If the
Milliseconds parameter is omitted, then the method will wait an
infinite period of time for the task to complete.
If the specified task has already completed at the time this
method is called, the method will return immediately without
causing the current thread to block. If the TimeElapsed
parameter has been specified, it will contain the number of milliseconds that
it took for the task to complete. If the TaskError parameter
has been specified, it will contain the last error code value that was
set by the worker thread before it terminated. If the TaskError value is zero, that
means that the background task was successful and no error
occurred. A non-zero value will indicate that the background task
has failed.
You should not call this method from the main UI thread with a
long timeout period to wait for a background task to complete. Windows
messages will not be processed while this method is blocked waiting
for the background task to complete, and this can cause your
application to appear non-responsive to the end-user. If you have a
GUI application and you need to determine if a background task
has finished, create a timer to periodically call the
TaskDone method. When it returns True
(indicating that the task has completed), you can safely call
TaskWait to obtain the elapsed time and last error code without
blocking the current thread.