473,412 Members | 2,054 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,412 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 1730
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.