Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cross Thread Call Error

Cross Thread Call Error

Scheduled Pinned Locked Moved Visual Basic
helpcsharptestingbeta-testingtutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • L Lost User

      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

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #2

      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 :-)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups