Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
Redacting a row in Excel based on a term. 17 54
What are the Important skill to have as Asp.net Developer 8 43
ADO.NET ENTITY DATA MODEL 3 32
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

24 Experts available now in Live!

Get 1:1 Help Now