Cyberactiva - webmaster tutorials, programming and videogames tricks

webmaster menu webmaster menu webmaster menu webmaster menu webmaster menu webmaster menu webmaster menu webmaster menu
  

Maintaining state using static members

Maintaining state using static members
I'm relatively new to web services and I stumbled on some code that
maintains state between calls using a class with static members. This
is not the actual code, but you get the gist:

[WebMethod]
void AddToRepository(string name, int v)
{
ClassWIthStaticMember.AddToRepository(name, v);
}
int GetFromRepository(string name)
return ClassWIthStaticMember.GetFromRepository(name, v);

It seems to work, at least in the short term, but I'm concerned that
this is a very unreliable way of doing things. I'm not sure what the
lifetime of those static methods will be.

Any thoughts?


Kirk, thanks for the reply.

My concern was that they will die too soon - not too late. So, is it
correct then that unless something disturbs the IIS AppDomain, such as
IISRESET or messing with one of the .config files, the static members
of classes accessed by the web service will live on?


Yep.

--
Kirk Allen Evans
Developer Evangelist
Microsoft Corporation
blogs.msdn.com/kaevans

=== This post provided "AS-IS" with no warranties and confers no rights ===
"Dmitri" wrote in message
news:1148925119.893632.10970@i39g2000cwa.googlegroups.com...
> Kirk, thanks for the reply.
>
> My concern was that they will die too soon - not too late. So, is it
> correct then that unless something disturbs the IIS AppDomain, such as
> IISRESET or messing with one of the .config files, the static members
> of classes accessed by the web service will live on?
>


Dmitri wrote:

> Kirk, thanks for the reply.
>
> My concern was that they will die too soon - not too late. So, is it
> correct then that unless something disturbs the IIS AppDomain, such as
> IISRESET or messing with one of the .config files, the static members
> of classes accessed by the web service will live on?

The app domain runs under a worker process in IIS.

IIS 6 (Win2003) will recycle worker processes after a period (look at
hte properties on your application pool in IIS). Additionally, there
are other factors used to determine if a worker process should be
recycled: age, time spent idle, number of requests serviced, number of
requests queued, and amount of physical memory consumed.

Read: http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/#S2

--
Deepak Shenoy
http://shenoyatwork.blogspot.com
Register for freeMembers Area
Web MarketingLast Web Marketing
Web MarketingLast Programming Tips
Web MarketingLast News


Web Marketing Links and links exchange .