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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. system.threading.timer

system.threading.timer

Scheduled Pinned Locked Moved C#
graphicsdocker
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.
  • D Offline
    D Offline
    dhol
    wrote on last edited by
    #1

    Hi I have done a program using thread(multithreading) with 3 text boxes, 3 labels and a button. such that when the button is clicked, Label 1 should become green color after the entered time period in text box1. Label 2 should become Yellow color after the entered time period in text box2. Label 3 should become Blue color after the entered time period in text box3. This I have done with three threads to start these processes. that is start the three threads in the buttonclick. Here is the coding part sing System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace multithreadtest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private Thread t1, t2, t3; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); t1 = new Thread(new ThreadStart(colourlabel1)); t2 = new Thread(new ThreadStart(colourlabel2)); t3 = new Thread(new ThreadStart(colourlabel3)); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.Font = new System.Drawing.Font

    G S 2 Replies Last reply
    0
    • D dhol

      Hi I have done a program using thread(multithreading) with 3 text boxes, 3 labels and a button. such that when the button is clicked, Label 1 should become green color after the entered time period in text box1. Label 2 should become Yellow color after the entered time period in text box2. Label 3 should become Blue color after the entered time period in text box3. This I have done with three threads to start these processes. that is start the three threads in the buttonclick. Here is the coding part sing System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace multithreadtest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private Thread t1, t2, t3; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); t1 = new Thread(new ThreadStart(colourlabel1)); t2 = new Thread(new ThreadStart(colourlabel2)); t3 = new Thread(new ThreadStart(colourlabel3)); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.Font = new System.Drawing.Font

      G Offline
      G Offline
      g00fyman
      wrote on last edited by
      #2

      there is a good threading example on msdn http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingtimerclasstopic.asp hth g00fy

      1 Reply Last reply
      0
      • D dhol

        Hi I have done a program using thread(multithreading) with 3 text boxes, 3 labels and a button. such that when the button is clicked, Label 1 should become green color after the entered time period in text box1. Label 2 should become Yellow color after the entered time period in text box2. Label 3 should become Blue color after the entered time period in text box3. This I have done with three threads to start these processes. that is start the three threads in the buttonclick. Here is the coding part sing System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace multithreadtest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private Thread t1, t2, t3; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); t1 = new Thread(new ThreadStart(colourlabel1)); t2 = new Thread(new ThreadStart(colourlabel2)); t3 = new Thread(new ThreadStart(colourlabel3)); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.Font = new System.Drawing.Font

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        First off, it isn't right to update UI controls from a different thread. This[^] might help you understand why. To answer your question, simply drag and drop a timer from the toolbox. Set its interval property, subscribe to its Elapsed event and you should be done. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        D 1 Reply Last reply
        0
        • S S Senthil Kumar

          First off, it isn't right to update UI controls from a different thread. This[^] might help you understand why. To answer your question, simply drag and drop a timer from the toolbox. Set its interval property, subscribe to its Elapsed event and you should be done. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

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

          Hi In c# windows form application, can u do a small program and make me understand this concept. I find it difficult while coming across this topic(system.threading.timer). Its really confusing me. so please with a small example can u sent the coding part and explain wht it does. pls do this help.. dhol

          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