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. C#
  4. Access to Object (TextBox or ListBox) from a Thread

Access to Object (TextBox or ListBox) from a Thread

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 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.
  • P Offline
    P Offline
    Patricio Tapia
    wrote on last edited by
    #1

    Example: .... Thread a = new Thread(method1); a.Start(); .... .... void method1() { textBox1.Text = "Hello"; } if i execute that code, they give me an InvalidOperationException error (access to textbox1 from another process) i try to call that method using an delegate, but not works another way is add this code: CheckForIllegalCrossThreadCalls = false; but i don't need to deactivated that how i can fixed?

    L 1 Reply Last reply
    0
    • P Patricio Tapia

      Example: .... Thread a = new Thread(method1); a.Start(); .... .... void method1() { textBox1.Text = "Hello"; } if i execute that code, they give me an InvalidOperationException error (access to textbox1 from another process) i try to call that method using an delegate, but not works another way is add this code: CheckForIllegalCrossThreadCalls = false; but i don't need to deactivated that how i can fixed?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you can access a Control only from the thread that created it, normally the main thread. Read up on Control.InvokeRequired and Control.Invoke() :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


      P 1 Reply Last reply
      0
      • L Luc Pattyn

        you can access a Control only from the thread that created it, normally the main thread. Read up on Control.InvokeRequired and Control.Invoke() :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        P Offline
        P Offline
        Patricio Tapia
        wrote on last edited by
        #3

        need some tutorial or example please (to understand)

        L 1 Reply Last reply
        0
        • P Patricio Tapia

          need some tutorial or example please (to understand)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          MSDN, Google and CodeProject are full of examples: almost every app that uses extra threads needs it! Here is an example in VB.NET[^], the last code snippet shows the principle.

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            MSDN, Google and CodeProject are full of examples: almost every app that uses extra threads needs it! Here is an example in VB.NET[^], the last code snippet shows the principle.

            Luc Pattyn [Forum Guidelines] [My Articles]


            this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


            P Offline
            P Offline
            Patricio Tapia
            wrote on last edited by
            #5

            Y readed and works fine my C# Code: public delegate void updatevalores(string dato); private void actualizarv(string datos) { if (this.InvokeRequired) { this.Invoke(new updatevalores(actualizarv),new object[]{dato}); return; } listBox1.Items.Add(dato.ToString()); } Thanks for all :rolleyes:

            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