Long latency when creating a new FileStream...

H

hzgt9b

Using VS2005, VB.NET,
I have a multi-threaded application. In one of my threads I need to
read a file as a binary stream. I am able to accomplish this using the
following code:

1 Dim BinaryFile As FileStream = New FileStream(<some file name>,
FileMode.Open, FileAccess.Read, FileShare.Read)
2 Dim BinRead As BinaryReader = Nothing
3 Me.BinRead = New BinaryReader(BinaryFile)
4 Me.BinRead.BaseStream.Seek(0, SeekOrigin.Begin)
5 Me.BinBytes = Me.BinRead.ReadBytes(<number of bytes to read>)

The code above works for me save one issue: on the first execution,
line 1 takes a really long time (4-7 seconds) to execute and don't
have any idea why.

Anyone have an idea what could be causing this latency and how to
avoid it?

Thanks for your attention to this...
 
H

hzgt9b

Using VS2005, VB.NET,
I have a multi-threaded application. In one of my threads I need to
read a file as a binary stream. I am able to accomplish this using the
following code:

1 Dim BinaryFile As FileStream = New FileStream(<some file name>,
FileMode.Open, FileAccess.Read, FileShare.Read)
2 Dim BinRead As BinaryReader = Nothing
3 Me.BinRead = New BinaryReader(BinaryFile)
4 Me.BinRead.BaseStream.Seek(0, SeekOrigin.Begin)
5 Me.BinBytes = Me.BinRead.ReadBytes(<number of bytes to read>)

The code above works for me save one issue: on the first execution,
line 1 takes a really long time (4-7 seconds) to execute and don't
have any idea why.

Anyone have an idea what could be causing this latency and how to
avoid it?

Thanks for your attention to this...

I believe that I figured this out - the latency is dependent on the
file size - I was testing with really large files thus getting a long
wait...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top