Question

  Asked: May 15 2008   5:34 AM GMT
  Asked by: Anishgk80


How shared functions work


ASP.NET, Memory management, Shared functions, Development, Web development, .NET Framework

Hi,

Very recently I had a passion for Shared methods. I have read many articles regarding usage of Shared methods and

variables and now I am confused whether it is a good choice or not. Let us discuss bu using a simple example. Consider

the class below

Class User
Public Shared Function InsertUser(Byval userId as integer, Byval userName as String) As Boolean
'Some Logic to insert user
End Function
End Class

In my web page (Say "AddUser.aspx") I creating a user as below

Dim boolInserted as Boolean = User.InsertUser(1, "Anish George")

I have the following questions

1) In the above case What happens when 2 threads simultaneously access the "InsertUser" function?

Next questions are regarding memory allocation

2) Consider 2 users are accessing the "AddUser.aspx" page from 2 different computers, simultaneously. In the server

memory will there be two representations of the function "InsertUser" (One memory allocation which belongs to User1 and

other which belong to User2)

3) What is an application domain? Consider that the function "InsertUser" was not shared and in the "AddUser.aspx" page

I am calling the "InsertUser" function as below

Dim obj as new User
Dim boolInserted as Boolean = obj r.InsertUser(1, "Anish George")

In this case ,in the server memory will there be two representations of the function "InsertUser"? Is this the case

where Application domain come into picture?

Kindly save me from my confusions by helping me find an answer to the above questions

Regards,
Anish George

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



1. Both users run the function at the same time.

2. No, the function will only be loaded into memory once.

3. I'm not sure. I don't think there will be two instances loaded into memory.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and Microsoft Windows.

Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register