Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.

Posted on 2009-04-20
Last Modified: 2012-05-06
I am using threading in 2005
Get this exception on thread cal l
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
Need to call this
Public Sub updateform()

        Dim charindex As Integer

        Dim linen As Integer

        linen = LineNo

        linen -= 1

        datenow = Now.ToString("HH:mm:ss")

        ts = datenow.Subtract(StartTime)

        charindex = SendMessage(SQLBox.Handle, EM_LINEINDEX, linen, 0)---exception here

        xStart = SQLBox.Find(NextLine, xStart + 1, RichTextBoxFinds.WholeWord)

        If charindex <> -1 Then

            SQLBox.SelectionStart = charindex

        End If

        Record_Progress.Value = LineNo

        Record_Counter.Text = (NumLines - LineNo)

        frmMain.StBar.Items.Item(3).Text = "Running time:  " & ts.ToString


    End Sub

Open in new window

Question by:RIAS
    1 Comment
    LVL 15

    Accepted Solution

    You need to update the UI from the same thread that created it. Use the following code to call updateform from the UI thread.

    frmMain.BeginInvoke(new MethodInvoker(addressof updateform))

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now