Hi,
In any ASP.NET application the life of the static variable sounds peculiar.
Consider a scenario like this,
public static int i = 0; //Static declaration
protected void Page_Load(objec t sender, EventArgs e)
{
if (i == 0)
{
Response.Write( "First time: i=" + i.ToString() );
}
else
{
Response.Write( "Else Part: i=" + i.ToString());
}
i++; //Increment the variable count by 1.
}
Now comes the game. Run the application....
First time it shows as: "First time: i=0"
Now stop the application (NOT the localhost), re-run the application
Now it shows output as: "Else Part: i=1" (again stop the application re-run) the 'i' value will be keep on incrementing only.
Can anybody tell me how to avoid this kind of behaviour (please don' tell avoid using static variables in web, already I have googled a lot and much of them tell the same thing, not to use static variable in web app, as if like an intellegent reply.)
Forget about above scenario.
Take this. If some xyz person has developed a class library project with lot of use of static variables (say business component). Since it is a class library project it is INDEPENDENT of where it is going to get plugged in (it can be windows app or web app it doesn't matter to xyz).
Now, if in your web application you are plugging in this DLL then what will happen to the consuming web application? I believe the 1st static scenario hell will occur here (and it is happing also).
So is there a wise solution for the above scenarios to avoid this kind of static hell???
with regards,
Krish TS
In any ASP.NET application the life of the static variable sounds peculiar.
Consider a scenario like this,
public static int i = 0; //Static declaration
protected void Page_Load(objec t sender, EventArgs e)
{
if (i == 0)
{
Response.Write( "First time: i=" + i.ToString() );
}
else
{
Response.Write( "Else Part: i=" + i.ToString());
}
i++; //Increment the variable count by 1.
}
Now comes the game. Run the application....
First time it shows as: "First time: i=0"
Now stop the application (NOT the localhost), re-run the application
Now it shows output as: "Else Part: i=1" (again stop the application re-run) the 'i' value will be keep on incrementing only.
Can anybody tell me how to avoid this kind of behaviour (please don' tell avoid using static variables in web, already I have googled a lot and much of them tell the same thing, not to use static variable in web app, as if like an intellegent reply.)
Forget about above scenario.
Take this. If some xyz person has developed a class library project with lot of use of static variables (say business component). Since it is a class library project it is INDEPENDENT of where it is going to get plugged in (it can be windows app or web app it doesn't matter to xyz).
Now, if in your web application you are plugging in this DLL then what will happen to the consuming web application? I believe the 1st static scenario hell will occur here (and it is happing also).
So is there a wise solution for the above scenarios to avoid this kind of static hell???
with regards,
Krish TS
Comment