Creating Tasks

Each time a vSphere server runs a method, it creates a Task and a corresponding TaskInfo data object. Some methods run synchronously and return data as the Task completes. But methods that end with _Task run asynchronously, and return a reference to a Task that will be created and completed as a processor becomes available. They are created to perform the functions in a non-blocking manner. Therefore, you must use the reference to the Task to monitor the status and results of the Task. vSphere operations that include the suffix _Task in their names are asynchronous and return Task references.

The Task object provides information about the status of the invoked operation through its TaskInfo data object. An instance of TaskInfo populates the info property of the Task managed object at runtime. By monitoring properties of the TaskInfo object, a client application can take appropriate action when the Task completes, or can handle errors if the Task does not complete successfully.

When a vSphere server creates a Task, it also creates a TaskEvent object. The TaskEvent object contains a copy of the TaskInfo object (TaskEvent.info). The TaskEvent copy of the TaskInfo object is a snapshot of the Task state at the time of its creation. It does not change after it is created. To find the current status of the task, use the Task.info.eventChainId property.