Author Topic: InvalidOperationException in OnConnectionEstablished - CLX 398s  (Read 1650 times)

WellsCPak

  • Newbie
  • *
  • Posts: 28
    • View Profile
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. =]

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
« Reply #1 on: June 22, 2015, 10:58:54 AM »
Do you have an event handler for the ConnectionEstablished event?

WellsCPak

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
« Reply #2 on: June 22, 2015, 01:16:07 PM »
No. Should I?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
« Reply #3 on: June 22, 2015, 01:30:24 PM »
No. I was just trying to see if I can replicate the problem.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: InvalidOperationException in OnConnectionEstablished - CLX 398s
« Reply #4 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