Cross Thread Call Error
-
Hi, everything I've read seems to tell me the following code should work.. even the MSDN example seems to suggest this. I'm new to .NET and I've been trying to get this working for several days, does anyone have any idea why this doesn't work? I'm getting "Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on." at ' Me.Text = "TEST" ' --------------------------------------------------- Imports System.Threading Public Class Form1 Delegate Sub TEST() Private TESTING As TEST Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ThreadBAH As New Thread(AddressOf DoCallBack) Me.TESTING = New TEST(AddressOf Me.TakeArgs) ThreadBAH.Start() End Sub Private Sub DoCallBack() Me.TESTING() End Sub Private Sub TakeArgs() Me.Text = "TEST" End Sub End Class --------------------------------------------- All help appreciated.
--- Assimilating Knowledge
-
Hi, everything I've read seems to tell me the following code should work.. even the MSDN example seems to suggest this. I'm new to .NET and I've been trying to get this working for several days, does anyone have any idea why this doesn't work? I'm getting "Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on." at ' Me.Text = "TEST" ' --------------------------------------------------- Imports System.Threading Public Class Form1 Delegate Sub TEST() Private TESTING As TEST Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ThreadBAH As New Thread(AddressOf DoCallBack) Me.TESTING = New TEST(AddressOf Me.TakeArgs) ThreadBAH.Start() End Sub Private Sub DoCallBack() Me.TESTING() End Sub Private Sub TakeArgs() Me.Text = "TEST" End Sub End Class --------------------------------------------- All help appreciated.
--- Assimilating Knowledge
This is quite a well known error. Just Google "Cross-thread operation not valid" and you'll see a heap of discussions and possible work arounds for this code.
...Steve
1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)