?
Solved

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

Posted on 2009-04-20
1
Medium Priority
?
660 Views
Last Modified: 2012-05-06
I am using threading in vb.net 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
        Application.DoEvents()
    End Sub

Open in new window

0
Comment
Question by:RIAS
1 Comment
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24185728
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

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Screencast - Getting to Know the Pipeline

621 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