c# - Web Service Singleton object problem -
i creating singleton object in first request web service , keeping in memory.
this works fine first few seconds. if make request 5 minutes later, can see singleton object created again? singleton object getting disposed after x no of minutes ?
how can make increase life-time of object forever ?
public sealed class singleton { static serverinstance instance = null; static readonly object padlock = new object(); singleton() { } public static serverinstance instance { { lock (padlock) { if (instance == null) { instance = new serverinstance(); } return instance; } } } ~singleton() { #if debug exceptionfactory.fatal("~singleton() called!"); #endif } } [webmethod] public string onreceiveevent(string objectxmldata, string objecttype) { if (!singleton.instance.initservercomplete) { initserver(); } return singleton.instance.onreceiveevent(objectxmldata, objecttype); } public void initserver() { if (!singleton.instance.initservercomplete) { singleton.instance.initserver(); singleton.instance.initservercomplete = true; gc.keepalive(singleton.instance); } }
there can no of reasons thinking aspnet process recyling.
Comments
Post a Comment