PowerShell ps = PowerShell.Create();ps.AddScript(myPsScript);foreach (PSObject result in ps.Invoke()) { dataGridView.Rows.Add( result.Members["Name"].Value, result.Members["Count"].Value, );}
dataGridView1.Invoke(new Action(() => { // the foreach code});
dataGridView1.Invoke(new Action(() => { // the foreach with invoke()});
Thread t = new Thread(() => { dataGridView1.Invoke(new Action(() => { // the foreach with invoke() });});t.Start()
dataGridView1.Invoke((MethodInvoker)delegate { // the foreach code with the ps invoke()});
as in the app is not responsive during the operation?
foreach (PSObject result in myCommand.Invoke()) { dataGridView.Rows.Add( result.Members["Name"].Value, result.Members["Count"].Value, );}