PDA

Click to See Complete Forum and Search --> : [RESOLVED] static on web vs windows


popskie
Feb 20th, 2007, 01:08 AM
Hi ,

Can anyone explain what is the difference between web app and windows app using static variable in terms of multiuser access?


Thanks,

Popskie

jmcilhinney
Feb 20th, 2007, 01:22 AM
There is no difference. A static member is a member of a class, not an instance of a class.

The difference that you perceive is that with a Windows application there would rarely be more than one instance of your application running on a system at once. With a Web app the same system is serving multiple users much of the time, so your static members are shared by all those users.

popskie
Feb 20th, 2007, 01:26 AM
I approved of what you said JM. Thanks

So, if posible its better to avoid using static in a web app. Am I right? Actually JM this app is already live in production but where lucky that until now its only one user used this site.hehehe
Again thanks.

jmcilhinney
Feb 20th, 2007, 02:06 AM
I don't know exactly how you're using it but many people abuse the static key word. If you've assigned a connection to a static variable in a class that may be used by more than one caller then that's a problem. A static variable is one for which there is, and should only be, one instance for the entire class. If you're making multiple connections then it's not logical that there should only be a single connection object.

popskie
Feb 20th, 2007, 02:15 AM
Ok jm your right.