Last post Jun 10, 2011 09:30 AM by mgs1808
Jun 10, 2011 06:25 AM|mgs1808|LINK
Suppose there is ASP.NET application using a VB class with some shared member...
Public Class test
Public Shared m_iData As Integer = 0
Now, if two distinct users use the application, how will the shared member behave? Will each user's thread have a separate location for that Integer? Or is it possible that one user's thread overwrites the other user's location?
Michael G. Schneider
Jun 10, 2011 06:34 AM|vincent1992|LINK
Yes, they both get a seperate location for the integer.
Jun 10, 2011 06:36 AM|Shakti Singh Tanwar|LINK
Shared data is always shared across users..That's why they are shared..so both will have same copy of data..If one thread overwrites second will have changed value...
Jun 10, 2011 07:08 AM|mgs1808|LINK
Thanks a lot for the answers. However, which one is correct?
I thought that "Public Shared Integer" meant it is shared within one execution of the application. However, for me it is unclear whether the "Shared" also influences different threads within IIS.
Jun 10, 2011 09:10 AM|Nareen|LINK
Second one is correct. Shared variable will be shared across the users.
refer this article
Jun 10, 2011 09:15 AM|kranthireddyr1|LINK
Nareen is correct, The second on is true :)
Jun 10, 2011 09:30 AM|mgs1808|LINK
Thanks a lot for the answers.
In the meantime I am "convinced" that the "shared across all users" answers is correct.
However, the mentioned knowledgebase article does not give a sufficient answer on the ASP.NET specifics. Obviously, it is fundamtally different, if a DLL is used from within an EXE or from within an ASP.NET application. With an EXE the DLL is loaded into
separate processes, and two "Public Shared Integer" are not shared. With an ASP.NET the DLL is not loaded into a separate process, so all "Public Shared Integer" are actually shared.
So, if anybody knows an articles describing the details of using Shared or Static in an ASP.NET application, I appreaciated to hear that.