A
Andrew Revell
I am writing an applicaiton on the following platform:
Advantech 133Mhz PCM3348.
Windows CE 5.0
Compact Framework.
As part of the application, I am writing information to file (that is,
compact flash) with the expressed intention of protecting it from
unexpected power failures etc.
What I am finding is that FileStream acts very strangely.....
The basic symptom is that sometimes after writing data to the stream
and flushing it, the file size is wrong... eg this works:
fstream.Write(record, 0, record.Length);
fstream.Write(record, 0, record.Length);
fstream.Flush();
(the size of the file is OK - record.Length * 2)
However if I do this:
fstream.Write(record, 0, record.Length);
fstream.Seek(0, SeekOrigin.Current);
fstream.Write(record, 0, record.Length);
fstream.Flush();
or even (!?!?):
fstream.Write(record, 0, record.Length);
fstream.Flush();
fstream.Write(record, 0, record.Length);
fstream.Flush();
the size of the file is only record.Length! WTF?!?
If I close the stream first (fstream.Close()), then it is fine - the
file size if correct.
BTW I measure the size of the file by either using FileInfo, or
rebooting and checking the size of the file. Also these results are
very repeatable - it works the same every time.
This has got me very confused. I don't want to close the stream every
time I write to it. That is expensive!
Any help glady received.
Advantech 133Mhz PCM3348.
Windows CE 5.0
Compact Framework.
As part of the application, I am writing information to file (that is,
compact flash) with the expressed intention of protecting it from
unexpected power failures etc.
What I am finding is that FileStream acts very strangely.....
The basic symptom is that sometimes after writing data to the stream
and flushing it, the file size is wrong... eg this works:
fstream.Write(record, 0, record.Length);
fstream.Write(record, 0, record.Length);
fstream.Flush();
(the size of the file is OK - record.Length * 2)
However if I do this:
fstream.Write(record, 0, record.Length);
fstream.Seek(0, SeekOrigin.Current);
fstream.Write(record, 0, record.Length);
fstream.Flush();
or even (!?!?):
fstream.Write(record, 0, record.Length);
fstream.Flush();
fstream.Write(record, 0, record.Length);
fstream.Flush();
the size of the file is only record.Length! WTF?!?
If I close the stream first (fstream.Close()), then it is fine - the
file size if correct.
BTW I measure the size of the file by either using FileInfo, or
rebooting and checking the size of the file. Also these results are
very repeatable - it works the same every time.
This has got me very confused. I don't want to close the stream every
time I write to it. That is expensive!
Any help glady received.