Here is some code to open a file with exclusive access for the purpose of
modifying it.
FileStream fstrm = new FileStream(inputFileName, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.None);
DataSet ds = new DataSet("MyDataSet");
ds.ReadXml(fstrm);
....edit a row here...
ds.AcceptChanges();
fstrm.Seek(0, SeekOrigin.Begin);
ds.WriteXml(fstrm, XmlWriteMode.IgnoreSchema);
fstrm.Close();
This works well except when there are multiple accesses to the same input
file and one is in the middle of changing it.... an access failure occurs.
So I set of trying to determine how to use a lock, or monitor, or mutex, or
async IO...so that others have to wait until the file is available before
they can access it rather than fail with an access failure. This is what I
am trying to figure out how to do.
The design criteria is that the access mechanism is designed within one
class. But this class is to be able to provide controlled IO to multiple
files.
Can this be done with the Monitor, Mutex, AutoResetEvent, or
ManualResetEvent or some other synchronization object?
Thanks,
Gery
--
Gery D. Dorazio
Development Engineer
EnQue Corporation
1334 Queens Road
Charlotte, NC 28207
(704) 377-3327 1 4581
Hi there... There are a couple of good articles that explain this subject in
depth. http://msdn.microsoft.com/msdnmag/is...asicinstincts/ http://msdn.microsoft.com/msdnmag/is...asicinstincts/
Hope this may help you,
Regards,
--
Angel J. Hernández M.
MCP - MCAD - MCSD - MCDBA http://groups.msn.com/desarrolladoresmiranda http://www.consein.com
"Gery D. Dorazio" <gd******@enque.net> escribió en el mensaje
news:Os**************@TK2MSFTNGP09.phx.gbl... Here is some code to open a file with exclusive access for the purpose of modifying it.
FileStream fstrm = new FileStream(inputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); DataSet ds = new DataSet("MyDataSet"); ds.ReadXml(fstrm); ...edit a row here... ds.AcceptChanges(); fstrm.Seek(0, SeekOrigin.Begin); ds.WriteXml(fstrm, XmlWriteMode.IgnoreSchema); fstrm.Close();
This works well except when there are multiple accesses to the same input file and one is in the middle of changing it.... an access failure occurs. So I set of trying to determine how to use a lock, or monitor, or mutex, or async IO...so that others have to wait until the file is available before they can access it rather than fail with an access failure. This is what I am trying to figure out how to do.
The design criteria is that the access mechanism is designed within one class. But this class is to be able to provide controlled IO to multiple files.
Can this be done with the Monitor, Mutex, AutoResetEvent, or ManualResetEvent or some other synchronization object?
Thanks, Gery
-- Gery D. Dorazio Development Engineer
EnQue Corporation 1334 Queens Road Charlotte, NC 28207 (704) 377-3327 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ryan |
last post by:
I have a problem with record locking / blocking within an application.
The app is quite straight forward. Written in Delphi 5 using BDE to
access a SQL 7 database (Win2K server).
Every so often...
|
by: black lee via DBMonster.com |
last post by:
Hi
here is what we want:
when process A selects a row for update, process B will only be allowed to
read only.
We are using DB2V8.2 Express Edition V8.2, and ODBC Driver is IBM DB2 ODBC...
|
by: swingingming |
last post by:
Hi, for 5 weeks, I finished my mdb project. Thanks to all you guys.
Now, I would like to put it on a server then 5-6 people can share it. I
heard about the splitting back-end database, put it on a...
|
by: ABCL |
last post by:
Hi All,
I am working on the situation where 2 different
Process/Application(.net) tries to open file at the same time....Or one
process is updating the file and another process tries to access...
|
by: George |
last post by:
Hi,
I am re-writing part of my application using C#. This application starts
another process which execute a "legacy" program. This legacy program writes
to a log file and before it ends, it...
|
by: dchadha |
last post by:
Hi,
I am working on application in C# which uses and stores data in xml
file. This app can use xml file from two different ways: (a) From User
Interface (Windows application) and (b) From...
|
by: shineofleo |
last post by:
Here is the situation: I wrote a VB programm, which stores all the
information in a single Access database file using jet engine. It
worked well, however one of my customs reported that there was...
|
by: Peter Duniho |
last post by:
I searched using Google, on the web and in the newsgroups, and found nothing
on this topic. Hopefully that means I just don't understand what I'm
supposed to be doing here. :)
The problem:
...
|
by: Zytan |
last post by:
This program DOESN'T deadlock due to attempt to reenter the same
lock! Why?
private static object m_lock = new object();
static void Main(string args)
{
lock (m_lock) { MyFunc(); }
}
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
| |