469,603 Members | 2,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

FileStream.Lock, FileStream.Unlock and its sync.

I've got multiple threads and processes that write to same
file. Before writing all threads / processes first lock
part of file and then write to file. If one thread /
process locks file, another threads / processes can not
lock this file again. And I want that all threads /
processes wait until first thread frees lock by calling
FileStream.Unlock. But I do not know what code should I
use that all threads / processes wait until first thread /
process unlock file.
My code :

FileStream FS = new FileStream
("\\Logs\\CriticalError.log",FileMode.Append,FileA ccess.Wri
BinaryWriter BW = new BinaryWriter(FS);

try {FS.Lock(0,10);}
catch (IOException E) { // This exception is thrown if
file is already locked
// Here I want that my thread waits until file is unlocked
and then I can lock file successfully.



What sync function should I use that my thread should
waited until file is unlocked ?

Can you give me short sample.

Thank you very much.
Jul 21 '05 #1
0 4286

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Daniel | last post: by
14 posts views Thread by Gary Nelson | last post: by
2 posts views Thread by valentin tihomirov | last post: by
45 posts views Thread by Chris Forone | last post: by
8 posts views Thread by Clive Dixon | last post: by
6 posts views Thread by DaveRook | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.