Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / January 2007

Tip: Looking for answers? Try searching our database.

File protection between webservice calls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nano2k - 22 Jan 2007 14:28 GMT
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 - 22 Jan 2007 22:26 GMT
You'll need execute the Dispose method instead of close.

> Hi
> My C# webservice uses a file to store some (short) information between
[quoted text clipped - 7 lines]
> Thanks.
> Adi.
nano2k - 23 Jan 2007 07:16 GMT
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:
> You'll need execute the Dispose method instead of close.
>
[quoted text clipped - 9 lines]
> > Thanks.
> > Adi.
Mariano Omar Rodriguez - 24 Jan 2007 00:00 GMT
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.

> Hi
>
[quoted text clipped - 32 lines]
>> > Thanks.
>> > Adi.
nano2k - 24 Jan 2007 06:47 GMT
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.
[quoted text clipped - 36 lines]
> >> > Thanks.
> >> > Adi.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.