Thread priorities. : Thread Priority « Thread « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Thread » Thread Priority 
20.7.1.Thread priorities.
using System; 
using System.Threading; 
 
class MyThread 
  public int count; 
  public Thread thrd; 
 
  public MyThread(string name) { 
    count = 0
    thrd = new Thread(this.run)
    thrd.Name = name; 
  
 
  void run() { 
    Console.WriteLine(thrd.Name + " starting.")
    do 
      count++; 
 
        Console.WriteLine("In " + thrd.Name)
    while(count < 10000)
 
    Console.WriteLine(thrd.Name + " terminating.")
  

 
class PriorityDemo 
  public static void Main() { 
    MyThread mt1 = new MyThread("High Priority")
    MyThread mt2 = new MyThread("Low Priority")
 
    mt1.thrd.Priority = ThreadPriority.AboveNormal; 
    mt2.thrd.Priority = ThreadPriority.BelowNormal; 
 
    mt1.thrd.Start()
    mt2.thrd.Start()
 
    mt1.thrd.Join()
    mt2.thrd.Join()
 
    Console.WriteLine()
    Console.WriteLine(mt1.thrd.Name + " thread counted to " + mt1.count)
    Console.WriteLine(mt2.thrd.Name + " thread counted to " + mt2.count)
  
}
High Priority starting.
In High Priority
In High Priority
In High Priority
In High Priority
...
^CTerminate batch job (Y/N)? n
20.7.Thread Priority
20.7.1.Thread priorities.
20.7.2.User Thread: Name, ApartmentState, IsAlive, Priority, ThreadState
20.7.3.Thread priorities: ThreadPriority.Highest, ThreadPriority.Lowest
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.