WinForm timed Start

Source: Internet
Author: User

System.Timers.Timer t; intsum =0; intQian; intBai; intShi; intGE;  PublicTest timed Start () {InitializeComponent (); }        //1. Using System.Timers.Timer//2.threadThread th;//Defining Threads        Private voidTest timed Start _load (Objectsender, EventArgs e) {TextBox1.Text="00.00"; T=NewSystem.Timers.Timer ( +); T.elapsed+=NewSystem.Timers.ElapsedEventHandler (theout);//execution of events at time of arrival;T.autoreset =true;//Whether the setting is executed once (false) or always executed (true);th=NewThread (calculate);//2. Threading MethodsTh. IsBackground =true; }        Private voidTheout (Objectsender, EventArgs e) {Sum++; Qian= SUM/ +; Bai= Sum% +/ -; Shi= Sum% -/Ten; GE= Sum%Ten; TextBox1.Text= Qian. ToString () + Bai. ToString () +"."+ Shi. ToString () +GE.            ToString (); Lbmessge. Items.insert (0,"I 1111"); }        Private voidButton1_Click (Objectsender, EventArgs e) {t.enabled=true;//whether to execute the System.Timers.Timer.Elapsed event;//If you do not write the following sentence there will be an exception. //Exception: Invalid inter-thread operation: access it from a thread that does not create a control "RichTextBox"//but that's not the best way. If only one process calls RichTextBox. You can use the following sentence//if more than one thread calls a control such as RichTextBox. You need to use a delegate. See the second method of threadControl.checkforillegalcrossthreadcalls=false; }        Private voidCalculate ()//the first method of threading        {             while(true) {sum++; Qian= SUM/ +; Bai= Sum% +/ -; Shi= Sum% -/Ten; GE= Sum%Ten; TextBox1.Text= Qian. ToString () + Bai. ToString () +"."+ Shi. ToString () +GE.                ToString (); Thread.Sleep ( +); }        }
  Public Partial classTest timed start: Form {System.Timers.Timer T; intsum =0; intQian; intBai; intShi; intGE;  PublicTest timed Start () {InitializeComponent (); }        //1. Using System.Timers.Timer//2.threadThread th;//Defining Threads        Private voidTest timed Start _load (Objectsender, EventArgs e) {TextBox1.Text="00.00"; Th=NewThread (calculate); Th. IsBackground=true; }         Private voidCalculate ()//the first method of threading        {             while(true) {sum++; Qian= SUM/ +; Bai= Sum% +/ -; Shi= Sum% -/Ten; GE= Sum%Ten; TextBox1.Text= Qian. ToString () + Bai. ToString () +"."+ Shi. ToString () +GE.                ToString (); Thread.Sleep ( +); }        }               Private voidButton1_Click (Objectsender, EventArgs e) {th.             Start (); Control.checkforillegalcrossthreadcalls=false;//same 2, not write will error                    }    }

System.Timers.Timer T;        int sum = 0;        int Qian;        int Bai;        int Shi;        int GE;        Public test timed Start () {InitializeComponent (); }

1. Use System.Timers.Timer//2.thread thread th;//define thread private void Test timed start _load (object sender, Eventar            GS e) {TextBox1.Text = "00.00";            t = new System.Timers.Timer (1000); t.elapsed + = new System.Timers.ElapsedEventHandler (theout);//The event is executed at time of arrival, T.autoreset = true;//setting is executed once (false) or Always executed (true);
th = new thread (calculate);//2. Threading method Th.        IsBackground = true; }

private void Theout (object sender, EventArgs e) {sum++;            Qian = sum/1000;            Bai = sum% 1000/100;            Shi = sum% 100/10;            GE = sum% 10; TextBox1.Text = Qian. ToString () + Bai. ToString () + "." + Shi. ToString () + GE.            ToString (); Lbmessge.        Items.insert (0, "I 1111"); }
private void Button1_Click (object sender, EventArgs e) {t.enabled = true;//whether to execute System.Timers.Timer.Elap            sed event;//If you do not write the following sentence there will be an exception. Exception: Invalid inter-thread operation: access it from a thread that is not creating a control "RichTextBox"//But this is not the best method. If only one process calls RichTextBox. You can use the following sentence//If there are multiple threads calling controls such as RichTextBox. You need to use a delegate. See the second method of thread
Control.checkforillegalcrossthreadcalls = false; }
private void Calculate ()//The first method of the thread {while (true) {sum++;                Qian = sum/1000;                Bai = sum% 1000/100;                Shi = sum% 100/10;                GE = sum% 10; TextBox1.Text = Qian. ToString () + Bai. ToString () + "." + Shi. ToString () + GE.                ToString ();            Thread.Sleep (1000); }        }

WinForm timed Start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.