Last post May 31, 2011 12:17 PM by libra_Dinesh
May 28, 2011 12:39 PM|ali_csharp|LINK
Yesterday I made a simple test program using VS2008,C#,ASP.NET (WAP), I created a very simple tennis like game, although fully in server side (I know a tennis game should not be implemented in server side), I declared some public static variables for controlling
ball and pads position, for instance ball_x and ball_y, then uploaded it in my host, then checked it in pc and laptop, first I ran it on pc, initally ball was positioned on middle of screen, so I waited some moments so that ball went to a corner, then checked
my url address in laptop, and YES! as I had guessed, ball was in screen corner, what is going on here? both of clients are referering to similar values? how can I prevent such a problem? can I arrange my system so that whenever a new user opens my page he/she
visits my inital page, I mean that users viewing my page (and changing server side variables) should not affect other user experience
thanks, any suggestion or idea would be highly appreciated
May 28, 2011 12:59 PM|MetalAsp.Net|LINK
Static variables are global to the entire application (meaning the same for all users), which explains the behavior you're seeing. You want to look at using Session, instead, because that's specific to each session.
May 31, 2011 12:17 PM|libra_Dinesh|LINK
One should use static variable only when the value stored in the variable is common to all the users using the web application.
for e.g incase you want to display total user logged into the website.
In your case you want the position of the balls tobe unique to all the users then I would suggest you not to use static variables.