AdvancedHMI Software

General Category => Support Questions => Topic started by: WellsCPak on June 22, 2015, 10:35:24 AM

Title: InvalidOperationException in OnConnectionEstablished - CLX 398s
Post by: WellsCPak on June 22, 2015, 10:35:24 AM
I've been seeing this error thrown from the comm driver on a hidden form for a few revisions of AHMI, I patched it by checking that the window handle is created before establishing a connection with the driver. It seems to work well so far, but if you have a better way to handle this error, please let me know. =]
Title: Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
Post by: Archie on June 22, 2015, 10:58:54 AM
Do you have an event handler for the ConnectionEstablished event?
Title: Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
Post by: WellsCPak on June 22, 2015, 01:16:07 PM
No. Should I?
Title: Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
Post by: Archie on June 22, 2015, 01:30:24 PM
No. I was just trying to see if I can replicate the problem.
Title: Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
Post by: Archie on June 22, 2015, 08:34:20 PM
Try this code and see how it works:

    Protected Overridable Sub OnConnectionEstablished(ByVal e As EventArgs)
        If m_SynchronizingObject IsNot Nothing AndAlso m_SynchronizingObject.InvokeRequired Then
            Dim Parameters() As Object = {Me, EventArgs.Empty}
            If m_SynchronizingObject IsNot Nothing Then
                If TypeOf (m_SynchronizingObject) Is System.Windows.Forms.Control AndAlso DirectCast(m_SynchronizingObject, System.Windows.Forms.Control).IsHandleCreated Then
                    m_SynchronizingObject.BeginInvoke(oced, Parameters)
                End If
            End If
        Else
            RaiseEvent ConnectionEstablished(Me, e)
        End If
    End Sub