Multi-thread in C #

xiaoxiao2021-03-05  22

*********************************************************** *********************************************************** ***** // Create a thread using System; using System.Threading; class Class1 {public void Method1 () {Console.WriteLine ( "Method1 is the starting point of execution of the thread");} public static void Main ( ) {Class1 newclass = new class1 (); thread thread1 = new thread (new strass.method1);}}

// Start thread1.start ();

// Name the thread.name = "Update Records Thread" with the relevant name as thread;

// Use features to understand the status of threads being executed isalivethreadState

// Terminate thread - merge thread thread1.abort (); thread1.join (); ** Normally call the abort () thread will not terminate immediately, need Join () cooperation

// Sub-thread - Restart the thread1.suspend () from the pending point, thread1.resume (); ** If the thread hangs itself, another thread is required to call Resume () to start this thread.

// Thread sleep Thread.Sleep (2000);

// exampleusing System; using System.Threading; class Class1 {public void Method1 () {Console.WriteLine ( "Method1 is the starting point of execution of the thread");} public static void Main () {Class1 newClass = new Class1 (); Thread Thread1 = new Thread (new ThreadStart (newClass.Method1)); Thread1.Name = "Sample Thread"; Thread1.Start (); Console.WriteLine ( "The execution of Sample Thread has started."); Thread1 .Abort ();

// thread state Thread.Start () - RunningThread.Sleep () - WaitSleepJoinThread.Suspend () - -SuspendRequested call from another thread; execution Thread.Suspned () - SuspendedThread.Resume () - RunningThread.Abort () - Calling -AbortRequested from another thread; execute thread.abort () - Aborted

// Thread Priority HIGHESTABOVENORMALNORMALBELOWNORMAL / LOWEST

Thread thread1 = new thread (New ThreadStart (newclass.method1)); thread1.priority = threadPriority.Highest; ** Highest priority stops executing all threads running on the system

转载请注明原文地址:https://www.9cbs.com/read-38728.html

New Post(0)