}
}
+ private void StopMonitor()
+ {
+ try
+ {
+ EventPipeClient.StopTracing(_processId, _sessionId);
+ }
+ catch (EndOfStreamException ex)
+ {
+ // If the app we're monitoring exits abruptly, this may throw in which case we just swallow the exception and exit gracefully.
+ Debug.WriteLine($"[ERROR] {ex.ToString()}");
+ }
+ }
+
public async Task<int> Monitor(CancellationToken ct, List<string> counter_list, IConsole console, int processId, int refreshInterval)
{
try
providerString = sb.ToString();
}
- var shouldExit = new ManualResetEvent(false);
+ ManualResetEvent shouldExit = new ManualResetEvent(false);
var terminated = false;
writer.InitializeDisplay();
});
monitorTask.Start();
- while(true)
+ Console.CancelKeyPress += (sender, args) => {
+ args.Cancel = true;
+ shouldExit.Set();
+ };
+ while(!shouldExit.WaitOne(250))
{
while (true)
{
if (shouldExit.WaitOne(250))
{
+ StopMonitor();
return 0;
}
if (Console.KeyAvailable)
pauseCmdSet = false;
}
}
-
if (!terminated)
{
- try
- {
- EventPipeClient.StopTracing(_processId, _sessionId);
- }
- catch (EndOfStreamException ex)
- {
- // If the app we're monitoring exits abruptly, this may throw in which case we just swallow the exception and exit gracefully.
- Debug.WriteLine($"[ERROR] {ex.ToString()}");
- }
+ StopMonitor();
}
return await Task.FromResult(0);