Interface IAsyncProcessRunner
Interface for running external processes asynchronously in the background. Supports monitoring state while running and provides process control.
Inherited Members
Namespace: Benday.Common
Assembly: Benday.Common.dll
Syntax
public interface IAsyncProcessRunner : IDisposable
Properties
| Edit this page View SourceErrorText
Get the current error text. Can be called while process is running.
Declaration
string ErrorText { get; }
Property Value
| Type | Description |
|---|---|
| string |
ExitCode
The exit code from the process. Returns -1 if not yet completed.
Declaration
int ExitCode { get; }
Property Value
| Type | Description |
|---|---|
| int |
HasCompleted
Indicates if the process has completed.
Declaration
bool HasCompleted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasStarted
Indicates if the process has been started.
Declaration
bool HasStarted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsError
Indicates if the process completed with an error.
Declaration
bool IsError { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsRunning
Indicates if the process is currently running.
Declaration
bool IsRunning { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSuccess
Indicates if the process completed successfully.
Declaration
bool IsSuccess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsTimeout
Indicates if the process timed out.
Declaration
bool IsTimeout { get; }
Property Value
| Type | Description |
|---|---|
| bool |
OutputText
Get the current output text. Can be called while process is running.
Declaration
string OutputText { get; }
Property Value
| Type | Description |
|---|---|
| string |
ProcessId
The process ID. Returns null if process has not started.
Declaration
int? ProcessId { get; }
Property Value
| Type | Description |
|---|---|
| int? |
RunTimeout
The timeout in milliseconds for the overall process run duration. If exceeded, the process is terminated and IsTimeout becomes true. Default is 0 (no timeout - runs indefinitely).
Declaration
int RunTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
StartInfo
The ProcessStartInfo object used to configure the process.
Declaration
ProcessStartInfo StartInfo { get; }
Property Value
| Type | Description |
|---|---|
| ProcessStartInfo |
StartupTimeout
The timeout in milliseconds for the process startup. The process must start within this time or a TimeoutException is thrown. Default is 5000ms (5 seconds).
Declaration
int StartupTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
UnderlyingProcess
Direct access to the underlying Process instance. Returns null if process has not started. Use with caution - prefer using the interface methods.
Declaration
Process? UnderlyingProcess { get; }
Property Value
| Type | Description |
|---|---|
| Process |
Methods
| Edit this page View SourceKill(bool)
Kill/stop the running process.
Declaration
void Kill(bool entireProcessTree = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | entireProcessTree | If true, kills the entire process tree. |
StartAsync(CancellationToken)
Start the process in the background (non-blocking).
Declaration
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. |
WaitForExitAsync(CancellationToken)
Wait for the process to complete.
Declaration
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. |