SocketTools .NET Edition

HttpClient.TaskWait Method (Int32, Int32, Int32, ErrorCode)

Wait for an asynchronous task to complete.

[Visual Basic]
Overloads Public Function TaskWait( _
   ByVal taskId As Integer, _
   ByVal timeWait As Integer, _
   ByRef timeElapsed As Integer, _
   ByRef taskError As ErrorCode _
) As Boolean
[C#]
public bool TaskWait(
   int taskId,
   int timeWait,
   ref int timeElapsed,
   ref ErrorCode taskError
);

Parameters

taskId
An integer value that specifies the unique identifier associated with a background task.
timeWait
An integer value that specifies the number of milliseconds to wait for the background task to complete.
timeElapsed
An integer value passed by reference that will contain the elapsed time for the task in milliseconds when the method returns.
taskError
An ErrorCode value passed by reference that will contain the last error code set by the asynchronous task.

Return Value

This method returns a boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

The TaskWait method waits for the specified task to complete. 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 timeWait parameter is zero, then this method will poll the status of the task and return immediately to the caller.

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. The timeElapsed parameter contain the number of milliseconds that it took for the task to complete. The taskError parameter 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.

See Also