B
blah, blah, blah
I'm developing a .Net web application and created many helper classes
often using static (shared in VB.Net) methods. Do I need to use the lock
(SyncLock) statement in these methods to prevent multiple web application
threads from using the same method at the same time?
For example, I have a static method that extracts information from a page
request cookie for use by other parts of the application. Since this
happens on every request I thought it would be a waste of resources to
create a new object just to provide the cookie method, so I made it
static. But then I thought if two different requests come into the
application milliseconds apart and two different threads request the same
static cookie method it could cause problems. The method is fast so it is
unlikely multiple threads will have a synchronization problem, but it
could happen (right?) and I do have other static methods take longer to
execute.
I'm not spawing a new thread to do any asynchronous processing, but it is
my understanding that IIS and ASP.Net are inherently multi-threaded when
dealing with page requests from different browsers/computers.
I've googled and searched all over the place but I can't find a clear
answer on if, when or how to use a lock statement in shared methods
specifically with web applications.
What are the general guidelines for using shared methods in web
applications?
Are there better methods for preventing synchronization problems than
using the lock statement?
Any pointers or tips are appreciated.
Dan
often using static (shared in VB.Net) methods. Do I need to use the lock
(SyncLock) statement in these methods to prevent multiple web application
threads from using the same method at the same time?
For example, I have a static method that extracts information from a page
request cookie for use by other parts of the application. Since this
happens on every request I thought it would be a waste of resources to
create a new object just to provide the cookie method, so I made it
static. But then I thought if two different requests come into the
application milliseconds apart and two different threads request the same
static cookie method it could cause problems. The method is fast so it is
unlikely multiple threads will have a synchronization problem, but it
could happen (right?) and I do have other static methods take longer to
execute.
I'm not spawing a new thread to do any asynchronous processing, but it is
my understanding that IIS and ASP.Net are inherently multi-threaded when
dealing with page requests from different browsers/computers.
I've googled and searched all over the place but I can't find a clear
answer on if, when or how to use a lock statement in shared methods
specifically with web applications.
What are the general guidelines for using shared methods in web
applications?
Are there better methods for preventing synchronization problems than
using the lock statement?
Any pointers or tips are appreciated.
Dan