Solved

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

Posted on 2007-11-13
3
329 Views
Last Modified: 2013-11-26
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
Comment
Question by:naafii_dxb
3 Comments
 
LVL 14

Expert Comment

by:cezarF
ID: 20277590
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 20279575
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now