| View previous topic :: View next topic |
| Author |
Message |
dxmedia
Joined: 11 Jul 2010 Posts: 5
|
Posted: Sun Jul 11, 2010 3:32 pm Post subject: Load external file - MemoryStream help |
|
|
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 |
|
 |
Softanics Site Admin
Joined: 18 Sep 2004 Posts: 1262 Location: Russia, St. Petersburg
|
Posted: Mon Jul 12, 2010 9:21 am Post subject: Re: Load external file - MemoryStream help |
|
|
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 |
|
 |
dxmedia
Joined: 11 Jul 2010 Posts: 5
|
Posted: Thu Jul 22, 2010 7:53 pm Post subject: |
|
|
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 |
|
 |
|