Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
            var stuffTask = DoStuff(cts.Token);

            var client    = new TraceClient();
            var traceTask = client.CollectAsync("trace.nettrace", cts.Token);

            await Task.WhenAll(stuffTask, traceTask);
        }
Ejemplo n.º 2
0
        private static async Task <int> StartTrace(string process, string output, int bufferSize, CancellationToken ct)
        {
            int    pid;
            string processName;

            try
            {
                (pid, processName) = GetProcessInfo(process);
            }
            catch (ArgumentException e)
            {
                await Console.Error.WriteLineAsync(e.Message);

                return(1);
            }

            var client = new TraceClient(pid, bufferSize);

            Console.WriteLine($"Starting trace of process {pid} ({processName}) - press Ctrl+C to stop...");
            await client.CollectAsync(output, ct);

            Console.WriteLine($"Trace written to '{output}'.");
            return(0);
        }