Share via


FileStream Read and Write Timeout

Question

Thursday, February 16, 2012 1:02 AM

Hello

I am making an attempt to set the Read and Write timeout on my FileStream objects. I was not able to retrieve sufficient information from msdn nor a google search. It appears that some folks are saying that the Read and Write timeouts will not work with FileStream objects.

Below is my Read FileStream object.

FileStream StreamSource = new FileStream(sourceFullPath, FileMode.Open, FileAccess.Read);

I am using VS 2010. When I probe the object to look at the ReadTimeOut property below is what I get.

ReadTimeout = '((System.IO.Stream)(objFileStreamSource)).ReadTimeout' threw an exception of type 'System.InvalidOperationException'

Any help would be appreciated.

Kemal Miller

All replies (4)

Thursday, February 16, 2012 1:14 AM âś…Answered | 1 vote

ReadTimeout is a property on Stream.  For most streams, including FileStream, this is not a property you can set - and will always throw this exception (by design).

From the documentation:

"The ReadTimeout property should be overridden to provide the appropriate behavior for the stream. If the stream does not support timing out, this property should raise an InvalidOperationException."

Available at: 

http://msdn.microsoft.com/en-us/library/system.io.stream.readtimeout.aspx

Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Thursday, February 16, 2012 5:31 AM | 1 vote

Hello,

The link below might help you.

I think you have to close filestream and requeststream after writing.

http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx


Monday, February 20, 2012 3:40 AM

Hi,

How is it going now with our friends' suggestions?
We are looking forward to hearing from you.

Have a nice day,

Leo Liu [MSFT]
MSDN Community Support | Feedback to us


Saturday, February 25, 2012 12:34 AM

Hello

I was a little bogged down so I lost track of this posting. I apologize for the delay in responding especially since this forum always has great quick responses to thread and the psosts within.

Unfortunatley I am unable to get much accomplish with the help that has been provided. I will do a better job describing what I am trying to accomplish. When I call the Read or Write method (property) of a file stream object I want to be able to limit how long the Read or Write process is allowed to attempt to finish the process.

When I try to use the method (property): Strem.WriteTimeout = 20; I get this erro: 'Timeouts are not supported on this stream".

Kemal Miller