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 7585375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:09:38+00:00 2026-05-30T19:09:38+00:00

What I am trying to do: There are three powershell scripts with different time

  • 0

What I am trying to do:
There are three powershell scripts with different time delays as shown below. I am trying to run them asynchronously in .NET and I followed this article to implement Asyncrhonous programming.

Where I am stuck:
The I am not able to retrieve output after the events are invoked. The scripts are being called but then the program ends and it shows “Press any key to continue” in console windows. I don’t what I am missing here. Any idea where I am doing wrong?

Info: JobRequest is a class that I use to pass around information keep track of jobs.

If you find a simpler and easy to understand explanation about Async programming then please provide it as all the article are confusing and long.

Sub Main()

        OurAsyncFunctionCalling("psDelayScript2.ps1", "-arg1 4 -arg2 5", 1)
        OurAsyncFunctionCalling("psDelayScript1.ps1", "-arg1 2 -arg2 3", 2)
        OurAsyncFunctionCalling("psDelayScript.ps1", "-arg1 1 -arg2 1", 3)

    End Sub
    Delegate Function AsyncMethodHandler(ByVal ScriptFile As String, ByVal ScriptParameters As String, ByVal id As String) As JobRequest

    Public Function RunScript(ByVal ScriptFile As String, ByVal ScriptParameters As String, ByVal id As String) As JobRequest
        Dim job1 As New JobRequest

        Dim start As New ProcessStartInfo
        Dim ScriptsFolder As String = "C:\BadTempScripts"

        ' start.FileName = "C:\WINDOWS\system32\cscript.exe"
        start.FileName = "powershell.exe"
        start.Arguments = ScriptsFolder + "\" + ScriptFile + " " + ScriptParameters
        start.UseShellExecute = False
        start.RedirectStandardOutput = True
        start.RedirectStandardError = True

        Dim myproc As New Process
        myproc.StartInfo = start
        myproc.Start()
        Dim so As System.IO.StreamReader
        Dim se As System.IO.StreamReader
        se = myproc.StandardError
        so = myproc.StandardOutput
        myproc.WaitForExit()
        job1.StandardError = so.ReadToEnd
        job1.StandardOutput = so.ReadToEnd
        Return job1
    End Function

    Public Sub OurAsyncFunctionCalling(ByVal strfile As String, ByVal strparameter As String, ByVal intid As Integer)
        Dim caller As AsyncMethodHandler
        caller = New AsyncMethodHandler(AddressOf RunScript)
        caller.BeginInvoke(strfile, strparameter, intid, AddressOf Callbackmethod, Nothing)
    End Sub

    Private Sub Callbackmethod(ByVal ar As IAsyncResult)
        Try

            Dim result As AsyncResult = CType(ar, AsyncResult)
            Dim caller As AsyncMethodHandler = CType(result.AsyncDelegate, AsyncMethodHandler)
            Dim returnvalue As JobRequest = caller.EndInvoke(ar)
            UpdateProcessCompleteLogic(returnvalue)
        Catch ex As Exception

        End Try
    End Sub
    Delegate Sub UpdateProcessCompleteHandler(ByVal jr As JobRequest)
    Public Sub UpdateProcessCompleteLogic(ByVal jr As JobRequest)
        Dim updatehandler As New UpdateProcessCompleteHandler(AddressOf updateprocess)

        Dim results As JobRequest = jr
    End Sub
    Sub updateprocess(ByVal jr As JobRequest)
        Console.WriteLine(jr.StandardError)
        Console.WriteLine(jr.StandardOutput)
    End Sub
  • 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-05-30T19:09:39+00:00Added an answer on May 30, 2026 at 7:09 pm

    I have found the solution to this mistake. In my asynchronous function, after I do the begin invoke call I ended the routine and the subroutine which was called asynchronously didn’t had any parent thread where it could report that the call was completed. The main thread should be running in order to see the results returned from the async callback function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are trying to build a High-Volume Orders Record System. There are three primary
I'm a Powershell newbie, trying to get a simple script to run. I have
I'm trying to get forms working with powershell, and I'm nearly there. I've got
I am using PowerShell and am trying to run the following command: .\test_cfdp.exe <
I am trying to write a Powershell script to run a general SQL command
Is there a better way than simply trying to open the file? int exists(const
Hey there, I am trying to get my signout button to work. This is
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
Hey there. I'm trying to write a small program that will read the four
Is there any open-source software that is trying to implement and emulate the human

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.