PowerShell-Docs icon indicating copy to clipboard operation
PowerShell-Docs copied to clipboard

How to Support Jobs - Redundant Methods

Open juvtib opened this issue 4 years ago • 0 comments

  • [ ] Why does void DoProcessLogic(bool asJob) exist if ProcessRecord() uses job.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.
  1. 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.

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.

juvtib avatar Mar 07 '21 09:03 juvtib