frightening control.invoke problems.

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

Hi all

I'm running into a nasty, intermittent problem when I try to use
control.invoke from within my CF application. My question is this: I
understand that I can only invoke a delegate of type EventHandler from
control.Invoke: does this include a delegate of type
MouseEventHandler? I was under the impression that MEH inherited from
EH...

If this is legit, any other idea why I might be getting the exception
below? My application ran in production for almost two weeks before
this appeared, and now it's happening every time the code is used...

Thoughts?

Thanks.

-Kevin

ArgumentException at
System.Reflection.RuntimeMethodInfo.InternalInvoke() at
System.Reflection.RuntimeMethodInfo.InternalInvoke() at
System.Reflection.RuntimeMethodInfo.Invoke() at
System.Reflection.MethodBase.Invoke() at TASK.Invoke() at
System.Windows.Forms.Control._InvokeAll() at
System.Windows.Forms.Control.InvokeHelper() at
Presentation.ShipFormController.ShipFormRfidEventHandler_Undo() at
Business.RfidReader.Reader_ReadNotify() at
Symbol.RFID.Reader.OnReadNotify() at
Symbol.Marshaller.SymbolMessageWindow.WndProc() at
Microsoft.WindowsCE.Forms.MessageWindow._WndProc() at
Microsoft.AGL.Forms.EVL.EnterModalDialog() at
System.Windows.Forms.Form.ShowDialog() at...etc.
 
It looks like you are using the 2.0 framework since you have a stack
trace. You can invoke whatever delegate you want, not just
EventHandler. Like Such:

Public Delegate Sub SomeDelegate()

Private Sub SomeMethod()
If (Me.InvokeRequired) Then
Dim dlg As New SomeDelegate(AddressOf SomeMethod)
Me.Invoke(dlg, New Object() {})
Return
End If
End Sub

It would help to see the snippet of code that is causing the problem
to diagnose the error.
 
Hi Chris

The Presentation.ShipFormController.ShipFormRfidEventHandler_Undo()
event Handler has the code:
....
if (!(tags.Count > 0))
{
this.btnDone.Invoke(new MouseEventHandler(ttPnlUndoByScan_MouseDown));

}
....

and the MouseEventHandler is:

void ttPnlUndoByScan_MouseDown(object sender, MouseEventArgs e)
{

disableRfid();
this.ttPnlUndoByScan.Visible = false;

}

It seems pretty basic. Have I missed something?

-Kevin
 
I would try this. Does this make sense? I sorry it's in VB.

Public Class YourForm

Private Delegate Sub UndoScanDelegate()

Private Sub ShipFormRfidEventHandler_Undo() Handles .....
If (tags.Count = 0) Then
UndoScan()
End If
End Sub

Private Sub UndoScan()
If (Me.InvokeRequired) Then
Dim dlg As New UndoScanDelegate(AddressOf UndoScan)
Me.Invoke(dlg, New Object() {})
Return
End If

disableRfid()
Me.ttPnlUndoByScan.Visible = false
End Sub

End Class
 
Thanks all

Chris, I will give your solution a try--it looks elegant.

I am still uneasy not knowing what I did wrong in the original
code... Because the error is intermittent, I can't really be
confident I have solved the problem unless I can identify the source
of the bug.

Any further ideas?

-Kevin
 
Chris:

Does the CF v2.0 support Asynchronous delegates? I have tried to use
Asynchronous delegates in a Win CE v5.0 application we're building. Even
though my Visual Studio 2005 compiles correctly, I get a run time exception
of "Not Supported" when I hit my Asynchronous delegate code.
 
Back
Top