www.f-in-box.com Forum Index www.f-in-box.com
F-IN-BOX
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
F-IN-BOX Home | DLL Edition | Delphi Edition | .NET Edition

Load external file - MemoryStream help

 
Post new topic   Reply to topic    www.f-in-box.com Forum Index -> .NET Edition
View previous topic :: View next topic  
Author Message
dxmedia



Joined: 11 Jul 2010
Posts: 5

PostPosted: Sun Jul 11, 2010 3:32 pm    Post subject: Load external file - MemoryStream help Reply with quote

Hi,

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:
        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
                Try
                    Stream.Write(buffer, 0, ReadBytes)
                Catch e As System.IO.IOException
                    ' Loading is interrupted
                    Exit While
                End Try
            End While

            Stream.Close()
            Handled = True
        End If



Thanks
Back to top
View user's profile Send private message
Softanics
Site Admin


Joined: 18 Sep 2004
Posts: 1262
Location: Russia, St. Petersburg

PostPosted: Mon Jul 12, 2010 9:21 am    Post subject: Re: Load external file - MemoryStream help Reply with quote

Hello,

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dxmedia



Joined: 11 Jul 2010
Posts: 5

PostPosted: Thu Jul 22, 2010 7:53 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.f-in-box.com Forum Index -> .NET Edition All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group