Thread Operation thread Hibernation

Source: Internet
Author: User

A thread's sleep is implemented through the sleep method of the thread class, and the IsAlive property of the instance of the thread class can determine if the thread is finished and the Sleep method is in the following format:

Thread instance. Sleep ();

The sleep time is measured in milliseconds.

Instance

Creates a method that outputs the current thread state without looping 5 times, then executes this method through the thread, and sleeps for 1 milliseconds during execution

Until this method completes

    classProgram { Public Static voidmth () {stringState ;  for(inti =1; I < +; i++)            {                //gets the current thread stateState =Thread.CurrentThread.ThreadState.ToString (); if(i%5==0) {Console.WriteLine ("Current thread State"+State ); }            }        }        Static voidMain (string[] args) {            //ThreadStart ts = new ThreadStart (MTH);Thread th =NewThread (MTH); Th.            Start (); //thread execution state, returns True if the thread sleeps 1 milliseconds for true             while(Th. IsAlive) {Console.WriteLine ("thread starts execution"); Thread.Sleep (1);        } console.read (); }

Thread Operation thread Hibernation

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.