public static object lock_updatesharevalue = new object();Now use this object in the webmethod to enable locking for an object in session
[WebMethod(EnableSession = true)] public int UpdateShareValue(string Shareidentifier,float Sharevalue) { lock(lock_updatesharevalue) { ///Update database with new share value } Session[Shareidentifier + "CurrentShareValue"] = Sharevalue; }So firstly session object is locked and then you are forcing a lock on a static object inside the webmethod that solves the issue of value failing to update when there are thousands of requests comming. Also point to note at this point is this method makes all the calls serialized and hence might reduce the performance and some of the calls might be waiting longer than expected so remember to increase the timeout in web.config
httpRuntime executionTimeout="10000" maxRequestLength="102400"Refer to this article about Session State Overview
The real danger is not that computers will begin to think like men, but that men will begin to think like computers. ~Sydney J. Harris
0 comments:
Post a Comment