User avatar
johan
GpsGate
Posts: 14293
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

Cannot call Invoke or InvokeAsync

Thu Aug 05, 2004 11:53 pm

Cannot call Invoke or InvokeAsync on a control until the window handle has been created.
SerialTools 1.11 and earlier only. Not releavant to later versions of SerialTools.

The complete error message is:

<font face="Courier New">Unhandled Exception: System.InvalidOperationException: Cannot call Invoke or
InvokeAsync on a control until the window handle has been created.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
</font id="Courier New">


You can get this error message if you are using OnRead and MultiThreading is set to false (default).

Here is three ways to address the problem:

1. If you have a form based application add the port object to the form. Read more here Port.OnRead.

Adding Port to a form in VB.NET
<font face="Courier New">Me.Controls.Add(objPort)</font id="Courier New">

Adding Port to a form in C#
<font face="Courier New">
this.Controls.Add(port);
</font id="Courier New">

2. If you have an application without forms (formless), set Port.MultiThreading to true. OnRead will now be called in a new thread, that is it is not synchronized with the main UI thread.

3. Use Port.Read instead.

Return to “Knowledge base SerialTools”