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 / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Access to file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christian Havel - 18 Jan 2008 15:55 GMT
Hi,

I have the following situation:

-> app1 writes data to a file
-> app2 (a service) is notified when the file is changed using the
FileSystemWatcher
-> app2 reads the last added data and should remove the read data from the
file

Well, I think I can get a problem, if app1 tries to write data to the file,
while app2 is removing the content from the file at the same time. How can
this problem be solved?
Christian
Ignacio Machin ( .NET/ C# MVP ) - 18 Jan 2008 16:00 GMT
Hi,

Can you use some other mechanism than a file?
Otherwise, can you create separated files each time App1 has something to
write (App2 can delete the consumed files afterwards)

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

> Hi,
>
[quoted text clipped - 11 lines]
> this problem be solved?
> Christian
Olie - 18 Jan 2008 16:16 GMT
For this very reason, when you try and write to a file the operating
system will lock the file preventing other applications from using it.
I think you can use the FileSystemMonitor to tell you when this lock
is removed. Then you know when it is safe to try and write to it.

The other way to do it is to ensure that only app1 actually writes to
the file. You could do this by having another file written to by app2
telling app1 what data needs to be deleted.
Christian Havel - 18 Jan 2008 16:38 GMT
Thanks for your help.
Is the file locked if I only read from it, too?
Christian

> For this very reason, when you try and write to a file the operating
> system will lock the file preventing other applications from using it.
[quoted text clipped - 4 lines]
> the file. You could do this by having another file written to by app2
> telling app1 what data needs to be deleted.
Olie - 18 Jan 2008 16:51 GMT
The file lock allows multiple readers but only one writer.

When the file is locked for writing only that application may write or
read from the file.

When a file is locked for reading any application can read from that
file and no application can write to it.
Christian Havel - 21 Jan 2008 08:29 GMT
Thanks Olie :-)

> The file lock allows multiple readers but only one writer.
>
[quoted text clipped - 3 lines]
> When a file is locked for reading any application can read from that
> file and no application can write to it.

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.