private void HandleOutput(int taskId, object?obj)
        {
            var output = new TaskOutput
            {
                TaskId = taskId,
                Object = (PSObject?)obj
            };

            _mainThread.InvokeOnMainThread(() => WriteOutput(output));
        }
 protected virtual void WriteOutput(TaskOutput output)
 {
     // This method makes WriteObject virtual to accommodate testing.
     WriteObject(output);
 }