vb .net variables in asp .net

M

Matt Mercer

Hi,

I have a simple question about vb .net variables. There is so much
info on variables out there I had trouble finding exactly what I am
looking for. Here is the question:

When I use a variable (for example Dim strWhatever As String) in
server code, is a new instance of the variable create for each user
who visits the page? I know I need session variables for user specific
information across multiple pages (there are other ways but session is
easiest). But if I'm using variables do something like figure the
interest on a loan payment, and the code is server side (not client
side), will there be a conflict if multiple people use my page
simultaneously or is it all separate? I know this is a rookie question
but I want to confirm the answer. Thanks. If you know of any good
links please send.
 
G

Greg Burns

It is all separate.

You have to use Session, Application, or Cache to share a variables between
users.

Greg
 
G

Greg Burns

Uh, well maybe not Session. :^)

Greg Burns said:
It is all separate.

You have to use Session, Application, or Cache to share a variables
between users.

Greg
 
L

Lucas Tam

(e-mail address removed) (Matt Mercer) wrote in
But if I'm using variables do something like figure the
interest on a loan payment, and the code is server side (not client
side), will there be a conflict if multiple people use my page
simultaneously or is it all separate?

It depends how you declare the variables. If you declare the variable as
static, it will be shared by all the users. If you declare it any other
way, it will be specific for each user.

You can share variables by using static, application, or cache variables.
 
G

Guest

P.S. My understanding is that if you declare a variable static/shared, it's
shared only across that *instance* of the application, and I'm not sure you
can know when/whether IIS decides to fire up a new instance of the app. Can
anybody confirm?

Bill
 
T

TJS

it's all separate, each request to the page gets reprocessed for each user.
Their inputs are processed and the variables only represent their
information. So, using something like Dim strWhatever As String is fine.
 
S

Scott Allen

A static/shared variable is shared within what's known as an app
domain. If IIS spins up a new instance of an ASP.NET application, it
will live in a new app domain.
 
S

Scott M.

You have to be careful here, "static" means something different in VB.NET
than it does in C#.

If you declare something as "static" in VB.NET, then the variable will
remain in scope even after its' local procedure ends. In VB.NET, if you
declare it as "shared", it is one value that is shared across all instances
of the class within one running application.
 
G

Guest

Scott, something I've been trying to get an answer to for some time: Can IIS
spin up multiple instances of my application *at the same time*. Or, does it
always end the one before it starts the other? Does it change if I'm working
in a web garden?

Bill
 
S

Scott Allen

Hi Bill:

Here is my understanding of the scenario - I think I can find some
official documentation on this if need be.

When a new instance of the application spins up it begins taking
requests before the old instance exists. All new requests are sent to
the new instance of the application while the old instance is allowed
to finish processing any requests it already has in the pipeline
(effectively a drain stop operation, in clustering terms).

I don't think there is any way to have more than one instance of an
ASP.NET application taking on new requests at the same time - except
with web gardening in IIS 6. Then you can have one worker process per
CPU - each taking incoming requests.

Even in a web garden though these are seperate appdomains. Each
instance will have it's own application state and static members.

Actually, I take back what I said in the third paragraph. There
probably are ways to have more than one active instance without
webGardens, but you'd have to write something with ISAPI, so it's
probably not worth the effort, know what I mean?

HTH,
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top