473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

File based process synchronization

Hi all,

I have a problem that should be quite common, but I'm not (yet) familiar with process synchronization in .NET:
There are several applications that write to a single file on disk. The apps open a FileStream with FileShare.None to prevent others
from reading garbage.

Now if a second process wants to open the file, it will fail. Currently I put the thread in a short Sleep and retry loop, but I'd
rather like to WaitForSingleObject() or so: The process 2 should be blocked until the first one closes the file and the file
(handle?) gets "signaled".

I came across the W32 Read/WriteFileEx(), which performs overlapped I/O, but I have a feeling that's a number too big...
Can anyone point me in the right direction?

Thanks a lot,
ulrich
Jul 21 '05 #1
2 1727
Ulrich Sprick <no******************@gmx.de> wrote:
I have a problem that should be quite common, but I'm not (yet)
familiar with process synchronization in .NET: There are several applications that write to a single file on disk.
The apps open a FileStream with FileShare.None to prevent others from
reading garbage.

Now if a second process wants to open the file, it will fail.
Currently I put the thread in a short Sleep and retry loop, but I'd
rather like to WaitForSingleObject() or so: The process 2 should be
blocked until the first one closes the file and the file (handle?)
gets "signaled".

I came across the W32 Read/WriteFileEx(), which performs overlapped
I/O, but I have a feeling that's a number too big... Can anyone point
me in the right direction?


I'd suggest using a Mutex which you wait for and signal.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks Jon, I'll give it a try.
ulrich

"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb im Newsbeitrag news:MP************************@msnews.microsoft.c om...
Ulrich Sprick <no******************@gmx.de> wrote:
I have a problem that should be quite common, but I'm not (yet)
familiar with process synchronization in .NET:

There are several applications that write to a single file on disk.
The apps open a FileStream with FileShare.None to prevent others from
reading garbage.

Now if a second process wants to open the file, it will fail.
Currently I put the thread in a short Sleep and retry loop, but I'd
rather like to WaitForSingleObject() or so: The process 2 should be
blocked until the first one closes the file and the file (handle?)
gets "signaled".

I came across the W32 Read/WriteFileEx(), which performs overlapped
I/O, but I have a feeling that's a number too big... Can anyone point
me in the right direction?


I'd suggest using a Mutex which you wait for and signal.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leon Mergen | last post by:
Hello, I'm currently in the process of implementing a file cache, and am looking for any existing design patterns. I hadn't had much luck with google, is anyone aware of a good file cache...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
7
by: Lalasa | last post by:
Hi, Can anybody tell me how many cpu cycles File.copy would take and how many cpu cycles File.Move would take? CFile::Rename in C++ takes just one cpu cycle. As there is no File.Rename in C#,...
3
by: Leo Heska | last post by:
Hi I haven't seen the following problem mentioned anywhere We have an application written in VB.NET which executes a batch file (named startJob.cmd). We have discovered that if that batch file...
2
by: Ulrich Sprick | last post by:
Hi all, I have a problem that should be quite common, but I'm not (yet) familiar with process synchronization in .NET: There are several applications that write to a single file on disk. The apps...
0
by: Rod | last post by:
I orginally posted this to microsoft.public.sqlserver.ce but had not received any responses. I have a CF.NET application (C#) with a SqlCE database. We had originally planned to use SQL...
2
by: Frank | last post by:
Hello all, I have to access a flat file (.txt or something) by two applications at the same time. For reading and writing. Is that possible and how? Thanks Frank
7
by: atlaste | last post by:
Hi, I have two different things I'd like to discuss here. Both are about cross-process synchronization of shared resources. The resources that are shared are: (1) an object writing to a file and...
1
by: vinayakkatkam | last post by:
public bool ProcessXCopy() { string XCopyArguments = "C:\\Documents and Settings\\Vinayak.Katkam\\Desktop\\SYNCHRONIZATION\\BASE-VERSION\\SDDS\\*.* " + "C:\\Documents and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.