Console.WriteLine($"Waiting for connection on {fullPort}");
Console.WriteLine($"Start an application with the following environment variable: DOTNET_DiagnosticPorts={fullPort}");
- IpcEndpointInfo endpointInfo = await server.AcceptAsync(ct);
- return new DiagnosticsClientHolder(new DiagnosticsClient(endpointInfo.Endpoint), endpointInfo, fullPort, server);
+ try
+ {
+ IpcEndpointInfo endpointInfo = await server.AcceptAsync(ct);
+ return new DiagnosticsClientHolder(new DiagnosticsClient(endpointInfo.Endpoint), endpointInfo, fullPort, server);
+ }
+ catch (TaskCanceledException)
+ {
+ if (!ct.IsCancellationRequested)
+ {
+ throw;
+ }
+ return null;
+ }
}
else
{
private CounterFilter filter;
private string _output;
private bool pauseCmdSet;
+ private ManualResetEvent shouldExit;
private bool shouldResumeRuntime;
private DiagnosticsClient _diagnosticsClient;
private EventPipeSession _session;
{
return 0;
}
+ shouldExit = new ManualResetEvent(false);
+ _ct.Register(() => shouldExit.Set());
DiagnosticsClientBuilder builder = new DiagnosticsClientBuilder("dotnet-counters", 10);
using (DiagnosticsClientHolder holder = await builder.Build(ct, _processId, diagnosticPort, showChildIO: false, printLaunchCommand: false))
{
+ if (holder == null)
+ {
+ return 1;
+ }
try
{
InitializeCounterList(counters, counter_list);
{
return 0;
}
+
+ shouldExit = new ManualResetEvent(false);
+ _ct.Register(() => shouldExit.Set());
+
DiagnosticsClientBuilder builder = new DiagnosticsClientBuilder("dotnet-counters", 10);
using (DiagnosticsClientHolder holder = await builder.Build(ct, _processId, diagnosticPort, showChildIO: false, printLaunchCommand: false))
{
+ if (holder == null)
+ {
+ return 1;
+ }
+
try
{
InitializeCounterList(counters, counter_list);
_renderer.Initialize();
- ManualResetEvent shouldExit = new ManualResetEvent(false);
- _ct.Register(() => shouldExit.Set());
Task monitorTask = new Task(() => {
try
{
Process process;
DiagnosticsClientBuilder builder = new DiagnosticsClientBuilder("dotnet-trace", 10);
bool shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort);
+ var shouldExit = new ManualResetEvent(false);
+ ct.Register(() => shouldExit.Set());
using (DiagnosticsClientHolder holder = await builder.Build(ct, processId, diagnosticPort, showChildIO: showchildio, printLaunchCommand: true))
{
+ // if builder returned null, it means we received ctrl+C while waiting for clients to connect. Exit gracefully.
+ if (holder == null)
+ {
+ return await Task.FromResult(ret);
+ }
diagnosticsClient = holder.Client;
if (shouldResumeRuntime)
{
}
}
- var shouldExit = new ManualResetEvent(false);
var shouldStopAfterDuration = duration != default(TimeSpan);
var rundownRequested = false;
System.Timers.Timer durationTimer = null;
- ct.Register(() => shouldExit.Set());
using (VirtualTerminalMode vTermMode = printStatusOverTime ? VirtualTerminalMode.TryEnable() : null)
{