Show / Hide Table of Contents

Class AsyncProcessRunner

Runs a process asynchronously in the background. Supports monitoring state while running, startup/run timeouts, and process control.

Inheritance
object
AsyncProcessRunner
Implements
IAsyncProcessRunner
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Common
Assembly: Benday.Common.dll
Syntax
public class AsyncProcessRunner : IAsyncProcessRunner, IDisposable

Constructors

| Edit this page View Source

AsyncProcessRunner(ProcessStartInfo)

Creates a new instance of AsyncProcessRunner.

Declaration
public AsyncProcessRunner(ProcessStartInfo startInfo)
Parameters
Type Name Description
ProcessStartInfo startInfo

The ProcessStartInfo to configure the process.

Properties

| Edit this page View Source

ErrorText

Get the current error text. Thread-safe, can be called while process is running.

Declaration
public string ErrorText { get; }
Property Value
Type Description
string
| Edit this page View Source

ExitCode

The exit code from the process. Returns -1 if not yet completed.

Declaration
public int ExitCode { get; }
Property Value
Type Description
int
| Edit this page View Source

HasCompleted

Indicates if the process has completed.

Declaration
public bool HasCompleted { get; }
Property Value
Type Description
bool
| Edit this page View Source

HasStarted

Indicates if the process has been started.

Declaration
public bool HasStarted { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsError

Indicates if the process completed with an error.

Declaration
public bool IsError { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsRunning

Indicates if the process is currently running.

Declaration
public bool IsRunning { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsSuccess

Indicates if the process completed successfully.

Declaration
public bool IsSuccess { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsTimeout

Indicates if the process timed out.

Declaration
public bool IsTimeout { get; }
Property Value
Type Description
bool
| Edit this page View Source

OutputText

Get the current output text. Thread-safe, can be called while process is running.

Declaration
public string OutputText { get; }
Property Value
Type Description
string
| Edit this page View Source

ProcessId

The process ID. Returns null if process has not started.

Declaration
public int? ProcessId { get; }
Property Value
Type Description
int?
| Edit this page View Source

RunTimeout

The timeout in milliseconds for the overall process run duration. Default is 0 (no timeout - runs indefinitely).

Declaration
public int RunTimeout { get; set; }
Property Value
Type Description
int
| Edit this page View Source

StartInfo

The ProcessStartInfo object used to configure the process.

Declaration
public ProcessStartInfo StartInfo { get; }
Property Value
Type Description
ProcessStartInfo
| Edit this page View Source

StartupTimeout

The timeout in milliseconds for the process startup. Default is 5000ms (5 seconds).

Declaration
public int StartupTimeout { get; set; }
Property Value
Type Description
int
| Edit this page View Source

UnderlyingProcess

Direct access to the underlying Process instance.

Declaration
public Process? UnderlyingProcess { get; }
Property Value
Type Description
Process

Methods

| Edit this page View Source

Dispose()

Disposes of the AsyncProcessRunner and kills the process if still running.

Declaration
public void Dispose()
| Edit this page View Source

Dispose(bool)

Disposes of managed and unmanaged resources.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

True if called from Dispose(), false if from finalizer.

| Edit this page View Source

Kill(bool)

Kill/stop the running process.

Declaration
public void Kill(bool entireProcessTree = false)
Parameters
Type Name Description
bool entireProcessTree

If true, kills the entire process tree.

| Edit this page View Source

StartAsync(CancellationToken)

Start the process in the background (non-blocking).

Declaration
public Task StartAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Optional cancellation token.

Returns
Type Description
Task

Task that completes when the process has started.

Exceptions
Type Condition
InvalidOperationException

Thrown if StartAsync() is called more than once.

TimeoutException

Thrown if the process does not start within StartupTimeout.

| Edit this page View Source

WaitForExitAsync(CancellationToken)

Wait for the process to complete.

Declaration
public Task WaitForExitAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Optional cancellation token.

Returns
Type Description
Task

Task that completes when the process has finished.

Implements

IAsyncProcessRunner
IDisposable

Extension Methods

ObjectAssertExtensions.ShouldBeNull<T>(T?, string)
ObjectAssertExtensions.ShouldBeSameAs<T>(T, T, string)
ObjectAssertExtensions.ShouldEqual<T>(T, T, string)
ObjectAssertExtensions.ShouldNotBeNull<T>(T?, string)
ObjectAssertExtensions.ShouldNotBeSameAs<T>(T, T, string)
ObjectAssertExtensions.ShouldNotEqual<T>(T, T, string)
ObjectAssertExtensions.ShouldBeOfType<T>(object?, string)
ObjectAssertExtensions.ShouldNotBeOfType<T>(object?, string)
  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com