synchronization of file resources

  • Thread starter Thread starter Ray Porter
  • Start date Start date
R

Ray Porter

Back when I was writing native ISAPI applications, it was always necessary
to protect resources like files within a synchronization object like a
critical section or a mutex. Is it still necessary to do that in ASP.Net
code? For example, if we have an application that is creating and writing
to a custom log file, should the file access logic be blocked by a
synchronization object of some sort or does the asp.net process protect you
from that sort of problem?

Thanks,
=================================
Ray Porter
Information Systems
Applications Development Manager
Division of University Advancement
University of North Carolina at Chapel Hill
Phone: (919) 259-9389
Fax: (919) 843-3314
Pager: (919) 216-4218

(e-mail address removed)
http://www.unc.edu/~dragon

Meddle not in the affairs of dragons for thou
art crunchy and taste good with ketchup
 
Back when I was writing native ISAPI applications, it was always
necessary to protect resources like files within a synchronization
object like a critical section or a mutex. Is it still necessary to
do that in ASP.Net code? For example, if we have an application that
is creating and writing to a custom log file, should the file access
logic be blocked by a synchronization object of some sort or does the
asp.net process protect you from that sort of problem?

You can still have concurrency issues with resources in ASP.NET, so
locking a file is still important. There is nothing inherent to the
system that saves you from concurrent access issues.

Coding multi-threaded code is much easier with .NET, however, and you
can use HTTP Handlers to "watch over" the process, much like the ISAPI
filters did in previous versions.

Peace and Grace,
Greg

--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Thanks, Greg. That's what I thought. I've found a lot of references to
protecting resources in .Net but nothing specific to ASP.Net, usually using
a system "named" mutex.

Ray
 
Thanks, Greg. That's what I thought. I've found a lot of references
to protecting resources in .Net but nothing specific to ASP.Net,
usually using a system "named" mutex.


You can often just use lock to lock a resource, if the issue is threads
within a single process. For multiple processes, you use a mutex. A
semaphore can also be used to limit threads, but since it is designed
more like a capacity, it is overkill if there is an exclusive lock.

Here is a site that you should look at, as it has fairly easy
explanations of threading, along with some code samples. I am not saying
it is the best site, but it is easy to get a grasp of the concepts.

The URL below hits the locking page on the site, which also covers mutex
(scroll down):
http://www.albahari.com/threading/part2.aspx

The author also hits EventWaitHandler, which may also be useful in your
code.

Peace and Grace,
Greg


--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top