Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ public int ProcessId
}
}

/// <summary>
/// Sets a value indicating whether the process has been terminated due to timeout or cancellation.
/// </summary>
private bool Canceled
private void Cancel()
{
set => GetWaitState()._canceled = value;
GetWaitState().Cancel(this);
}

protected override bool ReleaseHandle()
Expand Down Expand Up @@ -132,7 +129,7 @@ private ProcessExitStatus WaitForExitOrKillOnTimeoutCore(int milliseconds)

if (!waitState.WaitForExit(milliseconds))
{
waitState._canceled = SignalCore(PosixSignal.SIGKILL);
waitState.Cancel(this);
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
waitState.WaitForExit(Timeout.Infinite);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public int ProcessId
/// </summary>
private bool Canceled { get; set; }

private void Cancel()
{
#pragma warning disable CA1416 // PosixSignal.SIGKILL is supported on Windows via SignalCore
Canceled = SignalCore(PosixSignal.SIGKILL);
#pragma warning restore CA1416
}

protected override bool ReleaseHandle()
{
return Interop.Kernel32.CloseHandle(handle);
Expand Down Expand Up @@ -673,9 +680,7 @@ private ProcessExitStatus WaitForExitOrKillOnTimeoutCore(int milliseconds)
using Interop.Kernel32.ProcessWaitHandle processWaitHandle = new(this);
if (!processWaitHandle.WaitOne(milliseconds))
{
#pragma warning disable CA1416 // PosixSignal.SIGKILL is supported on Windows via SignalCore
Canceled = SignalCore(PosixSignal.SIGKILL);
#pragma warning restore CA1416
Cancel();
processWaitHandle.WaitOne(Timeout.Infinite);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public async Task<ProcessExitStatus> WaitForExitOrKillOnCancellationAsync(Cancel
var (handle, tcs) = ((SafeProcessHandle, TaskCompletionSource<bool>))state!;
try
{
handle.Canceled = handle.SignalCore(PosixSignal.SIGKILL);
handle.Cancel();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;

namespace System.Diagnostics
{
Expand Down Expand Up @@ -213,7 +214,17 @@ internal void ReleaseRef()
/// <summary>Associated process is a child that can use the terminal.</summary>
private readonly bool _usesTerminal;
/// <summary>A value indicating whether the process has been terminated due to timeout or cancellation.</summary>
internal volatile bool _canceled;
internal bool _canceled;
Comment thread
adamsitnik marked this conversation as resolved.

internal void Cancel(SafeProcessHandle process)
{
lock (_gate)
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
{
#pragma warning disable CA1416 // Signal is not supported on iOS/tvOS but Cancel is only called from supported platforms
_canceled = process.Signal(PosixSignal.SIGKILL);
#pragma warning restore CA1416
}
}

/// <summary>An in-progress or completed wait operation.</summary>
/// <remarks>A completed task does not mean the process has exited.</remarks>
Expand Down
Loading