S
showson1
Hi all!
I have some files that are basically a TIF with an ASCII header.
I wrote an app that reads in the file, pulls some values from the
header and writes out everything after the header as a new file.
I'm using binaryreader and binarywriter.
Everything functions fine, but the following loop causes 100% CPU
usage and I can't figure out how to get around this.
Here is a code sample that lists the declarations and the loop that's
causing the high CPU usage:
----------------------
Dim fsIn As FileStream = New FileStream(filename,
FileMode.OpenOrCreate)
Dim fsOut As FileStream = New FileStream(fsIn.Name & ".tif",
FileMode.Create)
Dim binWriter As BinaryWriter
Dim binReader As BinaryReader = New BinaryReader(fsIn)
binWriter = New BinaryWriter(fsOut)
Do While binReader.BaseStream.Position <
binReader.BaseStream.Length
binWriter.Write(binReader.ReadByte)
Loop
binWriter.Flush()
binWriter.Close()
binReader.Close()
binReader = Nothing
fsIn.Close()
fsIn = Nothing
fsOut.Close()
fsOut = Nothing
----------------------
Obviously I left some stuff out, but that's the part that's using the
CPU.
The binReader.BaseStream.Position picks up where the loop to find the
end of the header left off.
If anyone has any suggestions or tips as to what's going on and / or
how I can get around it I'd really appreciate it!
Thanks!
I have some files that are basically a TIF with an ASCII header.
I wrote an app that reads in the file, pulls some values from the
header and writes out everything after the header as a new file.
I'm using binaryreader and binarywriter.
Everything functions fine, but the following loop causes 100% CPU
usage and I can't figure out how to get around this.
Here is a code sample that lists the declarations and the loop that's
causing the high CPU usage:
----------------------
Dim fsIn As FileStream = New FileStream(filename,
FileMode.OpenOrCreate)
Dim fsOut As FileStream = New FileStream(fsIn.Name & ".tif",
FileMode.Create)
Dim binWriter As BinaryWriter
Dim binReader As BinaryReader = New BinaryReader(fsIn)
binWriter = New BinaryWriter(fsOut)
Do While binReader.BaseStream.Position <
binReader.BaseStream.Length
binWriter.Write(binReader.ReadByte)
Loop
binWriter.Flush()
binWriter.Close()
binReader.Close()
binReader = Nothing
fsIn.Close()
fsIn = Nothing
fsOut.Close()
fsOut = Nothing
----------------------
Obviously I left some stuff out, but that's the part that's using the
CPU.
The binReader.BaseStream.Position picks up where the loop to find the
end of the header left off.
If anyone has any suggestions or tips as to what's going on and / or
how I can get around it I'd really appreciate it!
Thanks!