Solved

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

Posted on 2007-11-13
3
337 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do you do a one to many list in .NET CORE? 2 36
Reading the web config for a running service on Windows 10 16 48
Help with exporting to excel 4 36
abstract class C# 1 31
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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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