Shared VB.NET modules

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a web application is first started and it uses a Module block, are global variables unique to the Request thread? What about a class module that declares shared variables. I created a test application and it appears to be unique to each Request. If this is a true statement is there a disadvantage to storing temporary state in a Module block? Is there any advantages to storing temporary state in Context.Items? Any reference to technical documentation would be greatly appreciated.
 
private or global has no bearing (this just controls scope). all module
variables private or global are shared across all threads in a web
application. in a class module any shared (static) variables are also shared
across all threads. you must use locking (unless the object is declared
threadsafe) when using shared variables in an asp.net application.

note: while there is a attribute to declare a variable as thread local
storage (as vb6 did), this does not work well with asp.net due to its
switching threads during a single page request (thread agility).

-- bruce (sqlwork.com)



Bruce Parker said:
When a web application is first started and it uses a Module block, are
global variables unique to the Request thread? What about a class module
that declares shared variables. I created a test application and it appears
to be unique to each Request. If this is a true statement is there a
disadvantage to storing temporary state in a Module block? Is there any
advantages to storing temporary state in Context.Items? Any reference to
technical documentation would be greatly appreciated.
 
Back
Top