O
Oenone
I'm upgrading a DLL from VB6 to VB.NET. The DLL gets called from an ASP.NET
web application.
In the VB6 code there is a module-level object which stores the context
about what the user is doing during each page request. This object is
initialised at the start of each request and populated with various data
retrieved from the URL, and is then repeatedly queried throughout the rest
of the page generation.
Am I right in thinking that there will be threading issues if I leave this
object in a module in VB.NET? If multiple IIS threads run simultaneously,
will they share the object instance or will they get one each? In VB6 they
got an instance each due to the apartment threading model but I'm suspicious
that this is not the case in VB.NET.
If the instance is shared between threads, this obviously makes it very
likely that the data will be corrupted (after it is initialised for user A,
user B makes a request and overwrites all the data. User A's code continues
to run and picks up all the values that user B's session stored).
Is there an easy way around this?
I looked at the ThreadStatic() attribute and this appears to do nearly what
I want, but it only works for Shared variables. As my object is defined
within a module, there is no need for it to be Shared (and indeed shared
variables aren't allowed in modules).
I'd be grateful for any insight anyone can provide.
My thanks in advance,
web application.
In the VB6 code there is a module-level object which stores the context
about what the user is doing during each page request. This object is
initialised at the start of each request and populated with various data
retrieved from the URL, and is then repeatedly queried throughout the rest
of the page generation.
Am I right in thinking that there will be threading issues if I leave this
object in a module in VB.NET? If multiple IIS threads run simultaneously,
will they share the object instance or will they get one each? In VB6 they
got an instance each due to the apartment threading model but I'm suspicious
that this is not the case in VB.NET.
If the instance is shared between threads, this obviously makes it very
likely that the data will be corrupted (after it is initialised for user A,
user B makes a request and overwrites all the data. User A's code continues
to run and picks up all the values that user B's session stored).
Is there an easy way around this?
I looked at the ThreadStatic() attribute and this appears to do nearly what
I want, but it only works for Shared variables. As my object is defined
within a module, there is no need for it to be Shared (and indeed shared
variables aren't allowed in modules).
I'd be grateful for any insight anyone can provide.
My thanks in advance,