Home All Groups Group Topic Archive Search About
Author
5 Jul 2006 10:47 AM
Rembo
Can anyone tell why I can't create the second filestream object?

Stream s1 = new FileStream("C:\\test.txt", FileMode.Open,
FileAccess.ReadWrite, FileShare.Read);

Stream s2 = new FileStream("C:\\test.txt", FileMode.Open,
FileAccess.Read, FileShare.Read);

FileShare.Read should make it possible just read the file after it is
already openend.

The IOException for the second stream is:
Message    "The process cannot access the file \"C:\\test.txt\" because it
is being used by another process."

Thanks in advance!

Author
5 Jul 2006 12:27 PM
Cowboy (Gregory A. Beamer)
You have ReadWrite access with the first object, which locks the file.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
Show quote
"Rembo" <remb***@hotmail.com> wrote in message
news:1152096426.692234.147080@b68g2000cwa.googlegroups.com...
> Can anyone tell why I can't create the second filestream object?
>
> Stream s1 = new FileStream("C:\\test.txt", FileMode.Open,
> FileAccess.ReadWrite, FileShare.Read);
>
> Stream s2 = new FileStream("C:\\test.txt", FileMode.Open,
> FileAccess.Read, FileShare.Read);
>
> FileShare.Read should make it possible just read the file after it is
> already openend.
>
> The IOException for the second stream is:
> Message "The process cannot access the file \"C:\\test.txt\" because it
> is being used by another process."
>
> Thanks in advance!
>

AddThis Social Bookmark Button