473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Module-level variables and multiple threads in IIS

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,

--

(O)enone
Nov 21 '05 #1
2 2951
you are correct.

in vb6, module variables are created as thread local storage (really nothing
to do with apartment model).

in vb.net they are true global variables shared between all threads. the
thread static attribute, will create cause shared variables to behave as
they did in vb6. but they shoudl not be used with asp.net. this is becuase
asp.net is thread agile, it can switch threads during the processing of a
request. this would cause your variable values to not be stable. indeed if
you use a vb6 com component, you need to set aspcompat mode, so that asp.net
will use the same thread to access the com component.

-- bruce (sqlwork.com)

"Oenone" <oe****@nowhere.com> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
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,

--

(O)enone

Nov 21 '05 #2
Hi Bruce,
in vb.net they are true global variables shared between all threads.
the thread static attribute, will create cause shared variables to
behave as they did in vb6. but they shoudl not be used with asp.net.
this is becuase asp.net is thread agile, it can switch threads during
the processing of a request.


Hmm, I wasn't aware of that -- just when I thought things were complicated
enough, a little bit more complexity comes along! :-/

How exactly should I go about using variables defined in modules then? From
what you're saying and what I'm reading about agile threads, it doesn't look
like this is going to be possible..?

--

(O)enone
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
8
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src = inspect.getsource(os) but there is no...
5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
8
by: Philippe C. Martin | last post by:
Hi, I'm getting pretty desperate here: The code below crashes on the last line (but works from a shell). The class 'BC' exists and the loop on self.__BC_EXEC_LIST passes fine. It's got to...
2
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first...
2
by: rh0dium | last post by:
Hi all, So I have a slice of code which calls other python code. I have started to take a real liking to the logging module, but I want to extend this into the called python code. I have no...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
6
by: Silfheed | last post by:
Heyas So we have the following situation: we have a testee.py that we want to automatically test out and verifiy that it is worthy of being deployed. We want our tester.py to test the code for...
3
by: kwatch | last post by:
What is the condition of module name which is available in 'from .. import ..' statement ? ---------------------------------------- import os print os.path # <module 'posixpath'...
0
by: Fredrik Lundh | last post by:
Jeff Dyke wrote: so how did that processing use the "mymodulename" name? the calling method has nothing to do with what's considered to be a local variable in the method being called, so...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.