File Share Question

  • Thread starter Thread starter > Adrian
  • Start date Start date
A

> Adrian

In an application in which FileShare is set.
Is it possible to go to say a file conntrol block
to ascertain the condition of the file, ie. if
someone else is working with the file? Or is
is it necessary to do all writing (not reading)
in a loop in which the user is kept till the
file is free again?

Adrian.
 
In an application in which FileShare is set.
Is it possible to go to say a file conntrol block
to ascertain the condition of the file, ie. if
someone else is working with the file? Or is
is it necessary to do all writing (not reading)
in a loop in which the user is kept till the
file is free again?


I believe if your filestream remains open - and depending on which mode you
have the filestream set to, you'll have control over the file.
 
Hi,

If a FileShare parameter is used and a
file is opened permitting others to read only,
what happens if some one tries to modify
the file, will he be set to wait in a loop
or will he get an error message?

Adrian.
 
I believe the .NEt framework will throw an exception if you try and open a
file for writing that has been opened elswjere for read only
 
If a FileShare parameter is used and a
file is opened permitting others to read only,
what happens if some one tries to modify
the file, will he be set to wait in a loop
or will he get an error message?

..NET will throw an exception.
 
Ok, thanks.
I think I have soved the problem by adding
code like so:

While(!fs.CanRead){}

That will keep the user waiting just a little
while till the file is free again. At least,
that is my expectation :)

(For the non-filestream files I have written
a simple block / unblock routine.)

Thank you again

Adrian.
 
Hi Adrian,

You might want to let some other threads get some processor time as well by
putting the thread to sleep:

while (!fs.CanRead)
{
System.Threading.Thread.Current.Sleep(200);
}
 
Dave Sexton said:
Hi Adrian,

You might want to let some other threads get some processor time as well by
putting the thread to sleep:

while (!fs.CanRead)
{
System.Threading.Thread.Current.Sleep(200);
}
*********************************
That is good advice, Thank you for it.
Adrian.
 
Your suggestion generated an error.
("... cannot be accessed as an instance reference ...")
Would System.Threading.Thread.Sleep(200);
be ok as well?

Please advise.

Adrian.
 
Hi,

Yes, sorry. I wrote that off the top of my head, which apparently is the
stupid part ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top