Groups | Blog | Home
all groups > asp.net webservices > january 2007 >

asp.net webservices : File protection between webservice calls


nano2k
1/22/2007 6:28:15 AM
Hi
My C# webservice uses a file to store some (short) information between
calls.
One method creates/updates the content of a file, another reads it.
What is the best method to avoid issues like "file is already opened by
another process", etc between calls?
Using Monitor.Enter(...) and Monitor.Exit(...) (or lock statement in
C#) will gracefully solve my problem in every situation?

Thanks.
Adi.
Mariano Omar Rodriguez
1/22/2007 7:26:13 PM
You'll need execute the Dispose method instead of close.

[quoted text, click to view]
nano2k
1/22/2007 11:16:45 PM
Hi

Thanks for your response.
Below is a code snipet from one of my webservice methods:

string fName = Path.Combine(path, "schemaDate.dat");
lock(m_syncToken) {
StreamWriter sw = File.CreateText(fName);
try{
sw.Write(m_schemaDate.ToString(CultureInfo.InvariantCulture));
}
finally{
sw.Close();
}
}

m_syncToken is defined as:
private static object m_syncToken;

My question is: is this pattern powerful enough to ensure exclusive
acces to only one request? I'm using .NET Framework 1.1 and IIS 5.1.


Mariano Omar Rodriguez a scris:
[quoted text, click to view]
Mariano Omar Rodriguez
1/23/2007 9:00:51 PM
This code only assures single access to the file if only a worker process is
running at the time.
Ahother thing is that you need call Dispose instead of Close.

[quoted text, click to view]
nano2k
1/23/2007 10:47:52 PM
Dispose method of what object?


Mariano Omar Rodriguez a scris:
[quoted text, click to view]
AddThis Social Bookmark Button