Skip to content

[API Proposal]: ProcessStartInfo.CreateSuspended, Process.Resume #94127

@sebastienros

Description

@sebastienros

Background and motivation

Currently I use ProcessStartInfo/Process.Start to launch processes with overridden environment variables, redirect standard input and output, and so forth.

I now need to use the CREATE_SUSPENDED flag so that I can modify the process after it's created and before it starts actual execution, but there's no way to pass this flag into ProcessStartInfo/Process.Start. Given that I still need to use all the other features of ProcessStartInfo, the only reasonable path I can see forward is to either copy or reimplement the entirety of the System.Diagnostics.Process code.

My proposal would also be cross-platform.

API Proposal

namespace System.Diagnostics;

public sealed partial class ProcessStartInfo
{
    public bool CreateSuspended { get; set; }
}

public partial class Process
{
    public bool Resume();
}

API Usage

var process = new Process()
{
    StartInfo = {
        FileName = executable,
        CreateSuspended = true,
        CreateNoWindow = true, // for reference only, as it has the same characteristics
    }
};

process.Start();

// Do whatever is needed with the process...

process.Resume();

Alternative Designs

I don't think these issues are duplicates since they adopt a different design that doesn't seem to get traction.

#71515
#90581

NB: @hach-que I copied your proposal and tried to make the API easier to get through the review process.

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions