Load external file - MemoryStream help

.NET Edition of the F-IN-BOX
Posts: 5
Joined: Sun Jul 11, 2010 3:26 pm

Load external file - MemoryStream help

Postby dxmedia » Sun Jul 11, 2010 3:32 pm


I am trying to modify this function that load an external file.

Instead of it writing bit by bit to the 'Stream' IOStream, I would like to write the data to a temporary MemoryStream, and then write it to 'Stream' all at once. This should be right before the 'Stream.Close()' line.

Can you help me ?

Here is my current code:

Code: Select all

        Dim FromStream As System.IO.Stream = Nothing

        FromStream = GetFileStream(Path)

        If Not FromStream Is Nothing Then

            Const Size As Integer = 256 * 1024
            Dim buffer(Size) As Byte
            Dim ReadBytes As Integer

            While True
                ReadBytes = FromStream.Read(buffer, 0, Size)
                If ReadBytes = 0 Then Exit While
                    Stream.Write(buffer, 0, ReadBytes)
                Catch e As System.IO.IOException
                    ' Loading is interrupted
                    Exit While
                End Try
            End While

            Handled = True
        End If


Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg

Re: Load external file - MemoryStream help

Postby Softanics » Mon Jul 12, 2010 9:21 am


dxmedia wrote:Can you help me ?

A quick question: before reading from the MemoryStream, have you seek its pointer to the beginning: MemoryStream.Position = 0 ?

Thank you.
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

Posts: 5
Joined: Sun Jul 11, 2010 3:26 pm

Postby dxmedia » Thu Jul 22, 2010 7:53 pm

Thank you very much,

Sorry for the late reply, but I found the solution.

Now, while the external file is being loaded into temporary memory, I can put a DoEvents in the While and this way the application does not freeze while loading swfs from external dlls (20-30 MB each).

Thanks Razin

Return to “.NET Edition”

Who is online

Users browsing this forum: No registered users and 2 guests