Y
Yash
Hi,
Can someone please explain to me what the
StreamReader.DiscardBufferedData method does?
The documentation says
"Use DiscardBufferedData to seek to a known location in the underlying
stream and then begin reading from this new point, or to read the
contents
of a StreamReader more than once."
I am not able to understand what exactly this means.
I am particularly looking for how this method manipulates the buffer.
In our VB .NET program, we spawn an FTP process to which we write
commands and read back the result. For this we use StandardInput and
StandardOutput property of the Process.
To send a command to the process, we do:
SendCommand:
Me.FTPProcess.StandardInput.WriteLine(cmd)
Me.FTPProcess.StandardOutput.DiscardBufferedData()
To read the result of the command we have:
ReadResult:
While Me.FTPProcess.StandardOutput.Peek() > -1
ftpResp = Me.FTPProcess.StandardOutput.ReadLine()
End While
When sending the command, if we do not use the DiscardBufferedData, we
noticed that the program does not read the result. The Peek function
returns -1. For some commands, the peek method also blocked
indefinitely.
If the DiscardBufferedData is kept, output from previous commands is
read followed by output of the recent command. This is probably what
is meant by the above line from the documentation.
We want to ensure that after every command, only the output of that
command is read.
Any ideas or suggestions?
Thanks
Can someone please explain to me what the
StreamReader.DiscardBufferedData method does?
The documentation says
"Use DiscardBufferedData to seek to a known location in the underlying
stream and then begin reading from this new point, or to read the
contents
of a StreamReader more than once."
I am not able to understand what exactly this means.
I am particularly looking for how this method manipulates the buffer.
In our VB .NET program, we spawn an FTP process to which we write
commands and read back the result. For this we use StandardInput and
StandardOutput property of the Process.
To send a command to the process, we do:
SendCommand:
Me.FTPProcess.StandardInput.WriteLine(cmd)
Me.FTPProcess.StandardOutput.DiscardBufferedData()
To read the result of the command we have:
ReadResult:
While Me.FTPProcess.StandardOutput.Peek() > -1
ftpResp = Me.FTPProcess.StandardOutput.ReadLine()
End While
When sending the command, if we do not use the DiscardBufferedData, we
noticed that the program does not read the result. The Peek function
returns -1. For some commands, the peek method also blocked
indefinitely.
If the DiscardBufferedData is kept, output from previous commands is
read followed by output of the recent command. This is probably what
is meant by the above line from the documentation.
We want to ensure that after every command, only the output of that
command is read.
Any ideas or suggestions?
Thanks