Async process - Start Subroutine when finished

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcolino

    Async process - Start Subroutine when finished

    Hi All,
    I'm using this code provided by Michael to run Async process:



    Now I have a new need. I have to start a Soubroutine when the Async
    process is finished.

    Many Thanks.

    --Marco
  • rowe_newsgroups

    #2
    Re: Async process - Start Subroutine when finished

    On Apr 8, 10:43 am, Marcolino <marco.pozzu... @gmail.comwrote :
    Hi All,
    I'm using this code provided by Michael to run Async process:
    >
    http://groups.google.com/group/micro...languages.vb/b...
    >
    Now I have a new need. I have to start a Soubroutine when the Async
    process is finished.
    >
    Many Thanks.
    >
    --Marco
    You can set up a callback from the BeginInvoke call that will fire
    when the async process finishes. Then you can do whatever you need
    from that method:

    Here's a quick console demo app:

    ////////////////
    Option Strict On

    Module Module1

    Public Delegate Sub AsyncDelegate()

    Sub Main()
    Console.WriteLi ne("Starting")
    Dim worker As New AsyncDelegate(A ddressOf AsyncMethod)
    worker.BeginInv oke(New AsyncCallback(A ddressOf
    AfterAsyncMetho d), Nothing)
    Console.WriteLi ne("Asnyc called")

    Console.Read()
    End Sub

    Private Sub AfterAsyncMetho d(ByVal ar As IAsyncResult)
    Console.WriteLi ne("AsyncMetho d finished. Do something else")
    End Sub

    Private Sub AsyncMethod()
    Console.WriteLi ne("Async is working")
    '// Simulate work
    System.Threadin g.Thread.Sleep( 1500)
    Console.WriteLi ne("Async is done working")
    End Sub

    End Module
    ////////////////

    Thanks,

    Seth Rowe [MVP]

    Comment

    • Spam Catcher

      #3
      Re: Async process - Start Subroutine when finished

      rowe_newsgroups <rowe_email@yah oo.comwrote in news:424eb9ff-3910-40c0-
      8bda-91d0741e3030@e3 9g2000hsf.googl egroups.com:
      Private Sub AfterAsyncMetho d(ByVal ar As IAsyncResult)
      Console.WriteLi ne("AsyncMetho d finished. Do something else")
      End Sub
      Should call EndInvoke here - to clean up the Async handler?

      --
      spamhoneypot@ro gers.com (Do not e-mail)

      Comment

      • kimiraikkonen

        #4
        Re: Async process - Start Subroutine when finished

        On Apr 8, 5:43 pm, Marcolino <marco.pozzu... @gmail.comwrote :
        Hi All,
        I'm using this code provided by Michael to run Async process:
        >
        http://groups.google.com/group/micro...languages.vb/b...
        >
        Now I have a new need. I have to start a Soubroutine when the Async
        process is finished.
        >
        Many Thanks.
        >
        --Marco
        Marco,
        You can also play with BackgroundWorke r control and its events such as
        RunWorkerComple ted, ProgressChanged events if it helps you.

        Regards,

        Onur Güzel

        Comment

        • Marcolino

          #5
          Re: Async process - Start Subroutine when finished

          On 8 Apr, 18:50, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
          On Apr 8, 5:43 pm, Marcolino <marco.pozzu... @gmail.comwrote :
          >
          Hi All,
          I'm using this code provided by Michael to run Async process:
          >>
          Now I have a new need. I have to start a Soubroutine when the Async
          process is finished.
          >
          Many Thanks.
          >
          --Marco
          >
          Marco,
          You can also play with BackgroundWorke r control and its events such as
          RunWorkerComple ted, ProgressChanged events if it helps you.
          >
          Regards,
          >
          Onur Güzel
          Hi I tryed this:
          worker.BeginInv oke(New AsyncCallback(A ddressOf AfterAsyncMetho d),
          Nothing)

          but i have a little problem.
          During sub AfterAsyncMetho d() i need to populate a listview present on
          main form. This is not possible because I cannot execute cross tread
          operation.
          I need that AfterAsyncMetho d() will be executed on the main tread of
          the application, after my async process is finished.

          Thanks a lot

          Comment

          Working...