IDashJob
Interface for controlling and monitoring the progress of asynchronous Jobs/Tasks.
The PowerShell example accepts a job returned by an operation such as IDashDevice::UploadSetup. Pass that object as $job after starting the operation on the intended device. It polls Completed so that the progress display can be updated instead of blocking in Wait. Completed does not imply success: check Failed and Error afterwards. The progress display is cleared even if an error occurs. Stopping the script does not cancel the device operation.
function Wait-DashJob {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[object]$Job,
[string]$Activity = 'Display operation'
)
$ErrorActionPreference = 'Stop'
try {
while (-not $Job.Completed) {
$percent = [int][Math]::Floor($Job.Progress * 100)
Write-Progress -Id 1 -Activity $Activity `
-Status "$percent% complete" -PercentComplete $percent
Start-Sleep -Milliseconds 200
}
if ($Job.Failed) {
throw "The job failed: $($Job.Error). Resolve the problem reported in the messages below and retry.`n$($Job.AllMessages)"
}
$Job.AllMessages
} finally {
Write-Progress -Id 1 -Activity $Activity -Completed
}
}
Wait-DashJob -Job $job -Activity 'Uploading display setup'var app = new ActiveXObject("GemsDashDesign.Application");
var device = false;
if (app) {
device = app.SelectedDevice;
}
if (device !== false) {
var job = device.UploadSetup(
"C:\\Folder\\setup.file"
);
while (!job.Completed) {
var prog = (job.Progress * 100) + "%";
WScript.StdOut.WriteLine(prog);
WScript.Sleep(500);
}
WScript.StdOut.WriteLine("Completed.");
if (job.Error && job.Error.length) {
WScript.StdOut.WriteLine("Error: " + job.Error);
}
}Contents
Properties
| Property | Description |
|---|---|
| Progress | Gets the progress of the Job as a value between 0.0 and 1.0 inclusive. |
| Completed | Indicates if the Job has completed. |
| Failed | Indicates if the Job failed. |
| Error | Gets the error status of the Job. |
| AllMessages | Gets a newline-separated string containing all messages generated by the Job. |
Public Methods
| Function | Description |
|---|---|
| Cancel | Cancels the Job. |
| Wait | Wait for the Job to complete. |
Properties
Progress
Gets the progress of the Job as a value between 0.0 and 1.0 inclusive.
double ProgressCompleted
Indicates if the Job has completed.
BOOL CompletedCheck the Error property to determine if there was a failure.
Failed
Indicates if the Job failed.
BOOL FailedSee Also: Error
Error
Gets the error status of the Job.
BSTR ErrorThis string will be empty of the Job completed without errors.
See Also: Failed
AllMessages
Gets a newline-separated string containing all messages generated by the Job.
BSTR AllMessagesPublic Methods
Method: Cancel
Cancels the Job.
HRESULT Cancel(void)Method: Wait
Wait for the Job to complete.
HRESULT Wait(void)This will block until the job is completed. Note that this will run the main application event loop from within the wait subroutine - so if the user interface is displayed then the user may still be able to interact with the application.