Hi,
I am writing a Web Service and I am having problems managing
concurrency of web methods.
Actually, I am interested in avoiding concurrency at all.
How can I ensure that only one web method is running at a given time?
I tried to wrap every webmethod inside an Application.Lock() /
Application.Unlock() pair, but it doesn't seem to be working.
The problem I am trying to solve is the following: on entry,
every web method reads in a status file, performs some computations,
and then writes down the file to disk. I must be sure that access to
this file is mutually exclusive.
Thank you in advance for your help
[MSFT] - 28 Apr 2004 04:08 GMT
Hi Paolo,
I think there are two approuch to achieve this:
1. Instead of a text file, you may consider use a database. ADO.NET will
take care the concurrency issue.
2. Create a type library for read/write the status file. In your web method
call the type library. In the type library, you can consider
ReaderWriterLock Class to control the read/write. For more inforamtion
about it, you can refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemThreadingReaderWriterLockClassTopic.asp
Luke
Microsoft Online Support

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Paolo Liverani - 28 Apr 2004 22:56 GMT
Ok, thank you Luke.
That's not exactly what I was looking for but if there is no other solution
I'll for the first one.
-Paolo
> Hi Paolo,
>
[quoted text clipped - 17 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Dilton McGowan II - 29 Apr 2004 05:30 GMT
> Hi,
> I am writing a Web Service and I am having problems managing
> concurrency of web methods.
> Actually, I am interested in avoiding concurrency at all.
> How can I ensure that only one web method is running at a given time?
Static constructor for the whole web service class? This is not something I
recommend from a performance angle.
> I tried to wrap every webmethod inside an Application.Lock() /
> Application.Unlock() pair, but it doesn't seem to be working.
[quoted text clipped - 3 lines]
> and then writes down the file to disk. I must be sure that access to
> this file is mutually exclusive.
Define a static class global object and lock( it ) ? This is somewhat
better, at least it allows some concurrency.
Side note is that if you are going to do something in all or many methods
creating a custom attribute class can be useful.