How shared functions work
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



