Dear JC.
when you create A static class. Only One copy remain in the Application
so far this is clear.
But do they share same copy or do they have different copy of them? The
answer is Yes they share the same copy of a static class.
try the sample code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Application["yahoo"] == null)
{
Random r = new Random();
Application.Add("yahoo", r.NextDouble());
}
Response.Write(TestClass.GetString());
}
}
public static class TestClass
{
public static string yahoostring = "Munna";
static TestClass()
{
Random r = new Random();
HttpContext.Current.Application["yahoo"] = r.NextDouble();
}
public static string GetString()
{
string s = yahoostring +
HttpContext.Current.Application["yahoo"].ToString();
return s;
}
}
Thanks
Md. Masudur Rahman
www.kaz.com.bd
KAZ Software Ltd.
Software outsourcing made simple...
JC wrote:
Suppose an ASP.Net project contains a public static class with public
methods and members that are used throughout the application. Of course
being static, there is only copy of the class within the application.
Now suppose two users access the Web site simultaneously. Does each
user see his/her own single copy of the static class, or do they
share the class, thus creating a problem that can only be solved
if one use blocks the other while using resources in the static
class?