Possible to terminate a sub that loads another sub?

K

Kathy Burke

Hi, I'm tired, so this question may be silly. I have a fairly long sub
procedure. Based on one condition, I load another sub with the
following:

If Session("GRN") = "complete" Then
txtScan.Text = Session("SN")
txtScan_TextChanged(sender, e)
Session("GRN") = ""
Exit Sub
End If

The txtScan_TextChanged sub loads another user page, which may be open
for a while (keeping the parent sub open as well). Then when the user
"ends" the child sub, the parent sub picks at line Session("GRN") = ""
and Exits the parent.

Just wondering, if this is the best/only way to do this? It disturbs me
a bit to see a page "loading" in the browser for such a period of time.
Make any sense at all?

Thanks,
Kathy
 
J

John Saunders

Kathy Burke said:
Hi, I'm tired, so this question may be silly. I have a fairly long sub
procedure. Based on one condition, I load another sub with the
following:

If Session("GRN") = "complete" Then
txtScan.Text = Session("SN")
txtScan_TextChanged(sender, e)
Session("GRN") = ""
Exit Sub
End If


Kathy,

Go get some sleep. Sub procedures don't "load" or keep their parent subs
open. You're very confused about something.
 
K

Kevin Spencer

I think I understand. Let me regurgitate this back to you in my own words
first, to make sure. You're concerned about how long it takes for your Page
to process because a Sub is being called (I believe this is what you mean by
"load") by another Sub, and the second Sub takes a long time to run, which
causes the first Sub to take a long time to run, as control is returned to
the first Sub only after the second Sub has finished. Correct? Again, if I
understand correctly, you're asking if there is a way to terminate the first
Sub after calling the second one. Right?

If so, the answer is going to be a little tricky to understand, as we'll
have to discuss threading. When a class loads, it loads into a thread of
execution. The thread follows a course of execution which can meander from
one Method to another until it is finished executing. It does precisely one
thing at a time. That is why the first Sub doesn't exit until the second Sub
is finished. The thread exits the first Sub at the point at which it calls
the second, runs through the second Sub (and any methods which the second
Sub calls), and returns to the point at which it left the first when it is
finished, and completes its run through the first.

..Net is multi-threaded, which means that you can run multiple threads of
execution at one time. Threading is complex and tricky, because when you
spawn multiple threads in a class, they all exist more or less independently
of one another, and execute asynchronously (meaning that their execution is
not coordinated or synchronized). In addition, they all belong to the same
context, and work with the same properties and methods in the class and
context from which they were spawned. There are ways of synchronizing
threads as well, when it is necessary to do so. This is accomplished by
establish "waiting Points" for threads, at which they must wait until
another thread "catches up" to continue executing.

In any case, if, for example, the second Sub is going to do something which
the first Sub and any subsequent "stops" along its thread of execution will
not be depending upon, you can spawn the second Sub in a separate thread.
When you do this, the Method call to the second Sub is executed, and the
first Sub continues on regardless of the state of execution of the second
Sub thread.

The following MSDN article should be helpful:

http://msdn.microsoft.com/library/d...en-us/dv_vstechart/html/vbtchusingthreads.asp

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
K

Kathy Burke

Kevin, excellent interpretation...that is exactly what I meant!

Thanks for the explanation and info...I'll go investigate the link you
gave me.

Kathy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top