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. reading a checkbox from another thread

reading a checkbox from another thread

Scheduled Pinned Locked Moved C#
5 Posts 4 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.
  • B Offline
    B Offline
    Bruce Coward
    wrote on last edited by
    #1

    I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:

    L 1 D 3 Replies Last reply
    0
    • B Bruce Coward

      I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      I didn't try it, but Invoke should do the trick to read a check box state.

      1 Reply Last reply
      0
      • B Bruce Coward

        I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:

        1 Offline
        1 Offline
        12Code
        wrote on last edited by
        #3

        Why use Invoke? Just read the control like usual..

            private void btnReadControlThread\_Click(object sender, EventArgs e)
            {
                Thread thread = new Thread(ThreadReadControl);
                thread.Start();
            }
        
            private void ThreadReadControl()
            {
                // read fr control is allowed
                MessageBox.Show("Enable status is " + cbEnableStatus.Checked.ToString());
        
                // below write to control is not allow, use Invoke
                // cbEnableStatus.Checked = true;
            }
        

        8.Kelvin()
        {
        while (!(the machine can program itself))
        Wont_stop_coding = true;
        }

        B 1 Reply Last reply
        0
        • 1 12Code

          Why use Invoke? Just read the control like usual..

              private void btnReadControlThread\_Click(object sender, EventArgs e)
              {
                  Thread thread = new Thread(ThreadReadControl);
                  thread.Start();
              }
          
              private void ThreadReadControl()
              {
                  // read fr control is allowed
                  MessageBox.Show("Enable status is " + cbEnableStatus.Checked.ToString());
          
                  // below write to control is not allow, use Invoke
                  // cbEnableStatus.Checked = true;
              }
          

          8.Kelvin()
          {
          while (!(the machine can program itself))
          Wont_stop_coding = true;
          }

          B Offline
          B Offline
          Bruce Coward
          wrote on last edited by
          #4

          Many thanks. Typical! me trying to overcomplicate things again. Cheers Bruce:thumbsup:

          1 Reply Last reply
          0
          • B Bruce Coward

            I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            Not sure about the safety of reading properties directly across threads as opposed to calling methods etc... I suppose you could provide a GetEnabled (and if needed SetEnabled) method that use the property's getter (and setter) and call Invoke on that.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            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