using System;
using System.Collections.Generic;
using System.Threading;
using Interop.VixCOM;
namespace Vestris.VMWareLib
{
///
/// A VixCOM job.
/// Implements synchronous execution of VixCOM tasks.
///
public class VMWareJob : VMWareVixHandle
{
private VMWareJobCallback _callback;
///
/// A VMWare job created with a job completion callback.
///
/// An instance of IJob.
/// Job completion callback.
public VMWareJob(IJob job, VMWareJobCallback callback)
: base(job)
{
_callback = callback;
// API-level errors aren't surfaced and the callback wait will never be set
bool completedImmediately = false;
VMWareInterop.Check(job.CheckCompletion(out completedImmediately));
}
///
/// Wait for the job to complete, timeout.
///
/// Timeout in seconds.
public void Wait(int timeoutInSeconds)
{
_callback.WaitForCompletion(timeoutInSeconds * 1000);
VMWareInterop.Check(_handle.WaitWithoutResults());
}
///
/// Wait for the job to complete, return a result.
///
/// Properties array.
/// Timeout in seconds.
/// Type of the property to return.
/// Job result.
public T Wait(object[] properties, int timeoutInSeconds)
{
_callback.WaitForCompletion(timeoutInSeconds * 1000);
return (T)Wait(properties);
}
///
/// Wait for the job to complete and enumerate results.
///
/// Properties to yield.
/// Timeout in seconds.
/// A results enumerator.
public IEnumerable