예제 #1
0
        /// <summary>
        /// Synchronous processing
        /// </summary>
        public static void Example1()
        {
            var          ps = PowerShell.Create().AddCommand("Get-Process");
            IAsyncResult pipeAsyncResult = ps.BeginInvoke();

            foreach (PSObject result in ps.EndInvoke(pipeAsyncResult))
            {
                ProcessItemHandler?.Invoke(new ProcessItem()
                {
                    Value = $"{result.Members["ProcessName"].Value,-20}{result.Members["Id"].Value}"
                });
            }
        }
예제 #2
0
        /// <summary>
        /// Asynchronous processing
        /// </summary>
        /// <returns></returns>
        public static async Task Example2Task()
        {
            await Task.Run(async() =>
            {
                await Task.Delay(0);
                var ps = PowerShell.Create().AddCommand("Get-Process");

                var pipeAsyncResult = ps.BeginInvoke();

                foreach (var result in ps.EndInvoke(pipeAsyncResult))
                {
                    ProcessItemHandler?.Invoke(new ProcessItem()
                    {
                        Value = $"{result.Members["ProcessName"].Value,-20}{result.Members["Id"].Value}"
                    });
                }
            });
        }