Thanks, Paul,
You are right about reading/sending the bytes (I should have been more
careful). I changed the code to make sure all bytes are read/sent.
Anyway, I solved the problem, which came from the audio recorder.
I am using OpenNetCF's OpenNETCF.Media.WaveAudio library for recording
the audio files.
======================
FileStream audioRecordingStream = new FileStream(path,
FileMode.Create);
Recorder recorder = new Recorder();
// Hook into the delegate for when the recording is finished.
recorder.DoneRecording += new
WaveFinishedHandler(recorderDoneRecording);
recorder.RecordFor(audioRecordingStream, MAX_RECORDING_TIME,
SoundFormats.Mono8bit11kHz);
======================
Users of my application can stop the recording before
MAX_RECORDING_TIME is reached. This is done by invoking
recorder.Stop(). The recorder will in turn invoke the DoneRecording
handle. The problem is that I MUST invoke recorder.Stop() in
recorderDoneRecording (the delegate/handle) again, else the resulting
file somehow seems corrupt (I can play it in a player, but
Socket.Send() breaks on it). Invoking recorder.stop() in the handle
solved my problem. Still, it' s weird that the error occurs only once
in a while. I'll report this back to OpenNetCF.
Thanks for your help!
On Jan 30, 11:23 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
[quoted text, click to view] no instrument no spam DOT com> wrote:
> So, you've come up with the number of bytes somehow and stored it in
> nrBytes. Maybe that's wrong. Note that just because you pass nrBytes to
>
> tmpFileStream.Read(bytes, 0, (int)nrBytes);
>
> DOES NOT mean that you will actually get back that many valid bytes in
> bytes. I think that your problem is very likely just some assumption that
> you're making that happens to be wrong (you're assuming that some allocation
> is successful; you're assuming that a read or a write has happened because a
> given method has returned; you're assuming that because you've asked for a
> send, that send has happened, etc.) I don't spot something completely wrong
> with the code, but it won't work perfectly every time and I'd suspect that
> some intermittent difference with the "perfect run" and you not reacting
> properly to that difference is what's causing the problem.