PowerShell-Docs
PowerShell-Docs copied to clipboard
How to Support Jobs - Redundant Methods
- [ ] Why does
void DoProcessLogic(bool asJob)exist ifProcessRecord()usesjob.ProcessJob()?
Alternatively, is it best practice to always create private SampleJob job = new SampleJob("Get-ProcAsJob") and use job.ProcessJob() even when asjob == false?
private SampleJob job = new SampleJob("Get-ProcAsJob");
protected override void ProcessRecord()
{
if (asjob)
{
JobRepository.Add(job);
WriteObject(job);
ThreadPool.QueueUserWorkItem(WorkItem);
}
else
{
job.ProcessJob();
foreach (PSObject p in job.Output)
{
WriteObject(p);
}
}
}
It doesn't seem like #5441 is resolved.
- [ ] Step 5 might need to be updated.
- If the cmdlet performs the work, call the System.Management.Automation.Cmdlet.WriteObject method to return a process object to the pipeline. If the work is performed as a job, add child job to the job.
- [ ] Writing a Cmdlet That Runs as a Background Job might be impacted.
Return the appropriate objects, depending on whether the cmdlet is run as a background job.
- [ ] The SDK might be affected.
// To load this cmdlet, create a module folder and copy the GetProcessSample06.dll // assembly into the module folder.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 98c13d87-511f-c9f3-ded2-4d546570bad8
- Version Independent ID: ddfef008-6b0f-6d6b-64f5-e0319fb728c0
- Content: How to Support Jobs - PowerShell
- Content Source: reference/docs-conceptual/developer/cmdlet/how-to-support-jobs.md
- Product: powershell
- Technology: powershell-conceptual
- GitHub Login: @joeyaiello
- Microsoft Alias: jaiello