[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Calling a subroutine and continuing the code after the subroutine without waiting for the subroutine to finish

Hello,

I have a sub to be called from sub main. But I want this call of the subroutine, not to wait for the subroutine to finish execution, but rather it should do its job aside and the sub main should continue the code after it. Plus this should be in iterative way, not only calling the subroutine once.

For example:

Sub Main()
        'Procedure level variables
        Dim x
        Dim y
        .........

                    For x=0 to 10

                            <code>.....
                            Extract(y)
                            <code2>.....

                    Next
end sub

sub Extract (byval value)
          <code 3>
end sub

So once Extract(y) is called, code 3 should execute on the side, and at the same time code 2 should continue and do its work even go to the next iterate.
0
naafii_dxb
Asked:
naafii_dxb
1 Solution
 
cezarFCommented:
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Threads can be Sync or Async.
The difference it that Sync is like inline code, Async work on a parallel processing, tho not waiting for it to finish.

Create the delegate and call BeginInvoke(), this will call the method on a separated thread.
Simply calling Invoke() will start a Sync processing and your code will still stop for the method to finish.

Be careful about UI... you cannot modify controls on a thread other than the one where they were created, that usually is the main thread. This means that every object that have visual representation cannot be changed on a different thread that the one where it was created.

This Google search returns a good set of articles about delegates.
http://www.google.pt/search?q=vb.net+delegates&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Cheers,
Alex
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now