Exception on Real Device

Hello
My app runs fine in the Emulator
but on the real device Ii get an exception (after a while and as I know so far not reproducable)
the Error is


MYApp.exe
ArgumentException
Value does not fall within the expected range.
at MISC.HandleAr()
at Form.ShowDialog()
at MainForm.XXXX_ServerStoppedMeasurement()
...


The MainForm.XXXX_ServerStoppedMeasurement() does the following:


privatevoid XXXX_ServerStoppedMeasurement(object sender,int timestamp,double Result)
{
// because method isInvokeRequired does not exist on .netCF i check it this way
if (this != sender)
{
this.BeginInvoke(new MesStoppedByServerNotify(XXXX_ServerStoppedMeasurement), this,timestamp, Result);
}
else
{
try
{
foreach (IDRIVERemoteUC usercontrol in ucList)
{
usercontrol.MeasurementStopped();
}
}
catch (Exception ex)
{ // simple ignore the error (can occur on connections timeouts ...)
string dummy = ex.Message; }
if (audio_in != null && audio_in.Recording)
audio_in.Stop();
if (form_result == null)
{
form_result = new Form_Result();
}
form_result.TheScore = Result;
form_result.Duration = timestamp;
form_result.ShowDialog();
this.button_startstop.MainText = Properties.Resources.StartStop_Start;
}
}


Sometimes it work, sometimes not, somebody know what I'm doing wrong?
[2083 byte] By [NorbertThek] at [2007-12-16]
# 1
I found the problem, probably its a bug in the .net Compactframework
the problem is, that the XXXX_ServerStoppedMeasurement can be called several times in the MainFrame Thread
I always thougt BeginInvoke is similar to PostThread Message. Meaning only one Message can be handled at one time, and the next message is handled when the first is finished. But when the server sends a second stop Msg while the user is still viewing the form_result.ShowDialog(); This line gets called a second time -> Argument Exception!
I even added a lock(form_result) around the showDialog method but in the debugger it looks like it is ignoring it, meaning the error is still happening.
I cannot use Invoke instead of BeginInvoke because the event is triggerd by a UDP Server, meaning the Server stop till the User closes the Result dialog!!

Somebody knows an alternativ solution?

NorbertThek at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices General...
# 2
Hi Norbert - as you found, BeginInvoke for .netcf works the same as the desktop, namely: "Executes a delegate asynchronously on the thread that the control's underlying handle was created on." It doesn't provide any blocking or serialization of your threading calls.

When reading your post, one thing that comes to mind is it appears you might want to explore using a queue'ing mechanism that serializes the data from your UDPServer. Your UDPServer would put data in one end and your processing thread would take it out from the other end. A buffer of sorts.

The addition of new data and processing of data could be done at different rates which would accomodate your modal dialog and not stop your server.

mike

MichaelLippMSFT at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices General...