Results 1 to 2 of 2

Thread: SerialPort and Control Updating in MDI form

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    7

    SerialPort and Control Updating in MDI form

    Hello guys,

    As my title implies i have the following problem, i am receiving data from serial port and i update a richtextbox in a MDI Form with the control.invoke method

    (Code in SerialPort.DataReceived Event)
    Code:
    If myTerminal.Visible Then
                myTerminal.MyRichTextBox1.Invoke(New MethodInvoker(Sub()
                                                                       myTerminal.MyRichTextBox1.AppendText(dataLine & vbCrLf)
                                                                   End Sub))
            End If
    But as a mdi form it has the ability to close and reopen. So when the serialport is sending data to richtextbox and the user click the close button and the form gets disposed. Then the error "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."... Any Idea????

    My regards,
    Ribben

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SerialPort and Control Updating in MDI form

    So set that variable to Nothing when the form closes and then test the variable for Nothing before you use it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width