Long latency when creating a new FileStream...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hzgt9b

    Long latency when creating a new FileStream...

    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(<som e file name>,
    FileMode.Open, FileAccess.Read , FileShare.Read)
    2 Dim BinRead As BinaryReader = Nothing
    3 Me.BinRead = New BinaryReader(Bi naryFile)
    4 Me.BinRead.Base Stream.Seek(0, SeekOrigin.Begi n)
    5 Me.BinBytes = Me.BinRead.Read Bytes(<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...
  • hzgt9b

    #2
    Re: Long latency when creating a new FileStream...

    On Mar 11, 11:04 am, hzgt9b <celof...@gmail .comwrote:
    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(<som e file name>,
    FileMode.Open, FileAccess.Read , FileShare.Read)
    2 Dim BinRead As BinaryReader = Nothing
    3 Me.BinRead = New BinaryReader(Bi naryFile)
    4 Me.BinRead.Base Stream.Seek(0, SeekOrigin.Begi n)
    5 Me.BinBytes = Me.BinRead.Read Bytes(<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...

    Comment

    Working...