コード例 #1
0
        public async Task <IEnumerable <IEndpointInfo> > GetEndpointInfoAsync(CancellationToken token)
        {
            var endpointInfoTasks = new List <Task <EndpointInfo> >();

            // Run the EndpointInfo creation parallel. The call to FromProcessId sends
            // a GetProcessInfo command to the runtime instance to get additional information.
            foreach (int pid in DiagnosticsClient.GetPublishedProcesses())
            {
                endpointInfoTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        return(EndpointInfo.FromProcessId(pid));
                    }
                    //Catch when the application is running a more privilaged socket than dotnet-monitor. For example, running a web app as administrator
                    //while running dotnet-monitor without elevation.
                    catch (UnauthorizedAccessException)
                    {
                        return(null);
                    }
                }, token));
            }

            await Task.WhenAll(endpointInfoTasks);

            return(endpointInfoTasks.Where(t => t.Result != null).Select(t => t.Result));
        }
コード例 #2
0
        public async Task <IEnumerable <IEndpointInfo> > GetEndpointInfoAsync(CancellationToken token)
        {
            var endpointInfoTasks = new List <Task <EndpointInfo> >();

            // Run the EndpointInfo creation parallel. The call to FromProcessId sends
            // a GetProcessInfo command to the runtime instance to get additional information.
            foreach (int pid in DiagnosticsClient.GetPublishedProcesses())
            {
                endpointInfoTasks.Add(Task.Run(() => EndpointInfo.FromProcessId(pid)));
            }

            await Task.WhenAll(endpointInfoTasks);

            return(endpointInfoTasks.Select(t => t.Result));
        }