Re: MemoryStream??

From: Charles A. Lackman (Charles_at_CreateItSoftware.net)
Date: 02/11/05


Date: Fri, 11 Feb 2005 10:27:06 -0800

Hello,

I have rewritten the stream directly to a file and still get the same error
(Freeze). I also changed the Session timeout on my server to last longer
(still same problem). Hmmm??

The Error I get is:

 unable to read data from transport connection

Code For CopyData:

Private Sub CopyData(ByVal FromStream As Stream, ByVal ToStream As Stream)
Dim intBytesRead As Integer
Dim Counter As Integer = 0
Const intSize As Integer = 1024
Dim bytes(intSize) As Byte
ProgressBar1.Step = 1024
intBytesRead = FromStream.Read(bytes, 0, intSize)
While intBytesRead > 0
ToStream.Write(bytes, 0, intBytesRead)
intBytesRead = FromStream.Read(bytes, 0, intSize)
end Sub

Chuck

"Fred Hirschfeld" <a@b.c> wrote in message
news:u5UgEZEEFHA.1012@TK2MSFTNGP14.phx.gbl...
> For one, if your intent is to store it in a file and never use it in
> memory
> then you simply need to put it into the file stream directly. I would
> recommend using a buffered loop to stream the file data from the response
> stream to the file stream until there is no more data.
>
> c# but easily translated and maybe this is what copy data is?:
> FileStream fos = new FileStream(Name, FileMode.Create);
> byte[] buf = new byte[4096];
> int bytes = 0;
> while((bytes = TheResponse.Read(buf, 0, 4096)) > 0) {
> fos.Write(buf, 0, bytes);
> }
> fos.close();
> TheResponse.close();
>
> Do you get any exceptions for the failure? Could it be a timeout that you
> are experiencing?
>
> Fred
>
> "Charles A. Lackman" <Charles@CreateItSoftware.net> wrote in message
> news:OqlZ0o6DFHA.2572@tk2msftngp13.phx.gbl...
>> Hello,
>>
>> I am working on an updater that Retrieves a file from a web page.
>>
>>
>> GetRequest.Method = "POST"
>>
>> SW = New StreamWriter(TheRequest.GetRequestStream)
>> SW.WriteLine(TransferName)
>> SW.Close()
>> TheResponse = TheRequest.GetResponse()
>> ms = New MemoryStream()
>> CopyData(TheResponse.GetResponseStream(), ms)
>> ms.Seek(0, SeekOrigin.Begin)
>> System.IO.Directory.CreateDirectory(TransferFolder)
>> Dim st As FileStream = New FileStream(CompleteName, FileMode.Create)
>> ms.WriteTo(st)
>> st.Close()
>> ms.Close()
>>
>> The application works good about 90% of the time I have noticed that when
>> the file is really big like 25 Megs, it stops sending at about 16 Megs.
> Is
>> this because the computer does not have enough memory to store the
> complete
>> file? or could it be something with the web page that is responding to
>> the
>> request? or could it be something else.
>>
>> Any suggestions will be greatly appreciated and even modifications to my
>> code above. I am not sure how to make the memory stream write to the
>> file
>> every Meg to test the theory.
>>
>> Thanks,
>> Chuck
>>
>>
>
>



Relevant Pages

  • Re: MemoryStream??
    ... I also changed the Session timeout on my server to last longer ... Private Sub CopyData(ByVal FromStream As Stream, ... Dim intBytesRead As Integer ... >> this because the computer does not have enough memory to store the ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: MemoryStream??
    ... I also changed the Session timeout on my server to last longer ... Private Sub CopyData(ByVal FromStream As Stream, ... Dim intBytesRead As Integer ... >> this because the computer does not have enough memory to store the ...
    (microsoft.public.dotnet.general)
  • Re: MemoryStream??
    ... I also changed the Session timeout on my server to last longer ... Private Sub CopyData(ByVal FromStream As Stream, ... Dim intBytesRead As Integer ... >> this because the computer does not have enough memory to store the ...
    (microsoft.public.dotnet.framework)
  • "401 unauthorized access" error
    ... //Create the Web request object. ... //Write all the zip file data to the request string ... Stream myRequestStream = myHttpWebRequest.GetRequestStream; ... intBytesRead = myFileStream.Read; ...
    (microsoft.public.dotnet.general)
  • Re: FileStream.Close() & GarbageCollection - Memory Leak Question
    ... There are two, that I can think of, major sources of memory leaks in an application. ... While you don't have to explicitly call code to free memory allocated in a managed world, you still have to make all the information you got about the lifetime for your data available to the garbage collector. ... stream and releases any resources ... Dispose/Close typically disposes of "scarce" resources, like handles, files, sockets. ...
    (microsoft.public.dotnet.languages.csharp)

Loading