Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > File protection between webservice calls

Reply
Thread Tools

File protection between webservice calls

 
 
nano2k
Guest
Posts: n/a
 
      01-22-2007
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.

 
Reply With Quote
 
 
 
 
Mariano Omar Rodriguez
Guest
Posts: n/a
 
      01-22-2007
You'll need execute the Dispose method instead of close.

"nano2k" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.
>


 
Reply With Quote
 
 
 
 
nano2k
Guest
Posts: n/a
 
      01-23-2007
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.Invaria ntCulture));
}
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:
> You'll need execute the Dispose method instead of close.
>
> "nano2k" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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.
> >


 
Reply With Quote
 
Mariano Omar Rodriguez
Guest
Posts: n/a
 
      01-24-2007
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.

"nano2k" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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.Invaria ntCulture));
> }
> 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:
>> You'll need execute the Dispose method instead of close.
>>
>> "nano2k" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) oups.com...
>> > 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.
>> >

>


 
Reply With Quote
 
nano2k
Guest
Posts: n/a
 
      01-24-2007
Dispose method of what object?


Mariano Omar Rodriguez a scris:
> 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.
>
> "nano2k" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> > 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.Invaria ntCulture));
> > }
> > 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:
> >> You'll need execute the Dispose method instead of close.
> >>
> >> "nano2k" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) oups.com...
> >> > 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.
> >> >

> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy protection / IP protection g Java 69 04-25-2006 04:10 PM
share function argument between subsequent calls but not between class instances! K. Jansma Python 7 02-21-2006 01:31 PM
MoVoIP - FREE MOBILE Inetrnet Phone Calls - FREE Internet Phone Calls ubifone VOIP 0 07-29-2005 04:31 PM
Sequence of constructor calls and destructor calls. Honne Gowda A C++ 2 10-31-2003 09:31 AM



Advertisments