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. how to change property of form in an other started thread?

how to change property of form in an other started thread?

Scheduled Pinned Locked Moved C#
questionhelptutorial
4 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    Sajjad Izadi
    wrote on last edited by
    #1

    Hi all, how can i change one of my forms properties in one other running thread? i mean i have thread1 which form is made in and thread2 which is resetting some of it properties. but doing so, my form goes into 'not responding' state (by operating system) and i have to end the application. what is the solution? msdn couldn't help. thanks :-D ;P

    H D 2 Replies Last reply
    0
    • S Sajjad Izadi

      Hi all, how can i change one of my forms properties in one other running thread? i mean i have thread1 which form is made in and thread2 which is resetting some of it properties. but doing so, my form goes into 'not responding' state (by operating system) and i have to end the application. what is the solution? msdn couldn't help. thanks :-D ;P

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      While you are waiting for someone to more completely answer your query, I would suggest that you research (MSDN and GOOGLE) the InvokeRequired property. This is a fundamental part of the solution and there are examples aplenty, which should at least get you thinking in the right areas.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      S 1 Reply Last reply
      0
      • H Henry Minute

        While you are waiting for someone to more completely answer your query, I would suggest that you research (MSDN and GOOGLE) the InvokeRequired property. This is a fundamental part of the solution and there are examples aplenty, which should at least get you thinking in the right areas.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        S Offline
        S Offline
        Sajjad Izadi
        wrote on last edited by
        #3

        thanks ;) but it is not really going to work. my form again goes to 'not responding'. why? :(

        modified on Tuesday, April 21, 2009 3:44 PM

        1 Reply Last reply
        0
        • S Sajjad Izadi

          Hi all, how can i change one of my forms properties in one other running thread? i mean i have thread1 which form is made in and thread2 which is resetting some of it properties. but doing so, my form goes into 'not responding' state (by operating system) and i have to end the application. what is the solution? msdn couldn't help. thanks :-D ;P

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

          I've constructed a very simple sample using a System.Timers.Timer as it runs on a seperate thread. You should be able to figure it out from this. [Edit] Changed the sample code to show how to call a method with parameters. [/Edit]

          using System;
          using System.Windows.Forms;
          namespace WindowsFormsApplication1
          {
          public partial class Form1 : Form
          {
          System.Timers.Timer timer;
          public Form1()
          {
          InitializeComponent();
          timer = new System.Timers.Timer();
          timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
          timer.Start();
          }

              void timer\_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
              {
                  /\* System.InvalidOperationException "Cross-thread operation not valid..."
                  will be thrown if you try to alter the property directly from a different thread \*/
                  if (this.InvokeRequired)
                  {
                      BeginInvoke(new MethodInvoker(delegate() { UpdateText(sender, e); }));
                  }
                  else
                  {
                      UpdateText(sender, e);
                  }
              }
              private void UpdateText(object sender, System.Timers.ElapsedEventArgs e)
              {
                  Text = e.SignalTime.ToString();
              }
          }
          

          }

          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)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          modified on Tuesday, April 21, 2009 4:50 PM

          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