Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:00:57+00:00 2026-06-04T11:00:57+00:00

As per this sample – http://msdn.microsoft.com/en-us/library/windows/desktop/ee706590(v=vs.85).aspx , I am trying to invoke my script

  • 0

As per this sample – http://msdn.microsoft.com/en-us/library/windows/desktop/ee706590(v=vs.85).aspx,

I am trying to invoke my script in an async way. But, at the same time, I want to give feedback to the GUI on the set of operations happening i.e. want to spit the Write-verbose stuffs happening behind the scenes parallely on the GUI.

I am confused in achieving this – because I see there is a DataReady event on the PipelineReader object ? Is it possible to somehow consume that w.r.t the MSDN sample above such that I can show feedback on the GUI ?

Conceptually, I am not able to relate this sample with the DataReady event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:00:58+00:00Added an answer on June 4, 2026 at 11:00 am

    Got it ! Here is the full code…

    Add a Rich Textbox = txtOutput on a Form first
    & Add a reference to

    C:\Program Files (x86)\Reference
    Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll

        IAsyncResult _invokeResult; 
    
        PowerShell _ps = PowerShell.Create();
    
        delegate void SetOutput(string value);
    
        // Monitor the DataAdded
        _ps.Streams.Verbose.DataAdded += new EventHandler<DataAddedEventArgs>(Verbose_DataAdded);
    
        var sr = new StreamReader(@"C:\MyScript.ps1");
        _ps.AddScript(sr.ReadToEnd());
        _invokeResult = _ps.BeginInvoke<PSObject>(null, null, AsyncInvoke, null);
    
    
       void Verbose_DataAdded(object sender, DataAddedEventArgs e)
       {
           System.Diagnostics.Debug.Print( ((PSDataCollection<VerboseRecord>) sender)[e.Index].ToString()) ;
    
           if (txtOutput.InvokeRequired)
           {
               string msg = ((PSDataCollection<VerboseRecord>) sender)[e.Index].ToString();
               txtOutput.Invoke(new SetOutput(Execute), new object[] { msg} );
           }
       }
    
    
    
       void AsyncInvoke(IAsyncResult ar)
       {
           // end
           try
           {
               _ps.EndInvoke(ar);
           }
           catch (Exception ex)
           {
                 // do something with the error...
           }
      }
    
    private void Execute(string msg)
            {
                txtOutput.SelectionFont = new Font(txtOutput.SelectionFont.FontFamily, 9.0f);
                txtOutput.AppendText(msg);
                txtOutput.ScrollToCaret();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://lakers.sonikastudios.com/gallery/sample-gallery-post-1/ That post has several pages using the quicktag of Wordpress. This post is
This is my sample site, http://box7.host1free.com/~avodes/ and I am having trouble on the blog
As per this MSDN article: W3C Extended Log File Format (IIS 6.0) It says
I'm trying to build a Synergy AutoStart script as per this article , the
I've been trying to follow this tutorial for deploying a WCF sample to IIS
Per this question (see comments near the bottom), I was wondering if anyone knows
I am having the same issues as per this question: WCF not deserializing JSON
I am putting a label on a UIToolbar (per this tip: Adding a UILabel
I've started to become a Good Citizen, as per this question here: Domain compatibility:
Referencing this post: ruby on rails average per day I'm getting the average per

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.