<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FThread%2FThread_Properties</id>
		<title>Csharp/C Sharp/Thread/Thread Properties - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FThread%2FThread_Properties"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Properties&amp;action=history"/>
		<updated>2026-04-29T16:10:09Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Properties&amp;diff=1061&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Properties&amp;diff=1061&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:19Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Properties&amp;diff=1062&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Properties&amp;diff=1062&amp;oldid=prev"/>
				<updated>2010-05-26T11:42:54Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Current Thread Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
class Program {&lt;br /&gt;
    static int interval;&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        interval = 100;&lt;br /&gt;
        ThreadPool.QueueUserWorkItem(new WaitCallback(StartMethod));&lt;br /&gt;
        Thread.Sleep(100);&lt;br /&gt;
        ThreadPool.QueueUserWorkItem(new WaitCallback(StartMethod));&lt;br /&gt;
        Console.ReadLine();&lt;br /&gt;
    }&lt;br /&gt;
    static void StartMethod(Object stateInfo) {&lt;br /&gt;
        DisplayNumbers(&amp;quot;Thread &amp;quot; + DateTime.Now.Millisecond.ToString());&lt;br /&gt;
        Console.WriteLine(&amp;quot;Thread Finished&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    static void DisplayNumbers(string GivenThreadName) {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Starting thread: &amp;quot; + GivenThreadName);&lt;br /&gt;
        for (int i = 1; i &amp;lt;= 8 * interval; i++) {&lt;br /&gt;
            if (i % interval == 0) {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Count has reached &amp;quot; + i);&lt;br /&gt;
                Console.WriteLine(&amp;quot;CurrentCulture: &amp;quot; + Thread.CurrentThread.CurrentCulture.ToString());&lt;br /&gt;
                Console.WriteLine(&amp;quot;IsThreadPoolThread: &amp;quot; + Thread.CurrentThread.IsThreadPoolThread.ToString());&lt;br /&gt;
                Console.WriteLine(&amp;quot;ManagedThreadId: &amp;quot; + Thread.CurrentThread.ManagedThreadId.ToString());&lt;br /&gt;
                Console.WriteLine(&amp;quot;Priority: &amp;quot; + Thread.CurrentThread.Priority.ToString());&lt;br /&gt;
                Console.WriteLine(&amp;quot;ThreadState: &amp;quot; + Thread.CurrentThread.ThreadState.ToString());&lt;br /&gt;
                Thread.Sleep(1000);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrate thread priorities==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Demonstrate thread priorities. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
using System.Threading; &lt;br /&gt;
 &lt;br /&gt;
class MyThread { &lt;br /&gt;
  public int count; &lt;br /&gt;
  public Thread thrd; &lt;br /&gt;
 &lt;br /&gt;
  static bool stop = false; &lt;br /&gt;
  static string currentName; &lt;br /&gt;
 &lt;br /&gt;
  /* Construct a new thread. Notice that this  &lt;br /&gt;
     constructor does not actually start the &lt;br /&gt;
     threads running. */ &lt;br /&gt;
  public MyThread(string name) { &lt;br /&gt;
    count = 0; &lt;br /&gt;
    thrd = new Thread(new ThreadStart(this.run)); &lt;br /&gt;
    thrd.Name = name; &lt;br /&gt;
    currentName = name; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Begin execution of new thread. &lt;br /&gt;
  void run() { &lt;br /&gt;
    Console.WriteLine(thrd.Name + &amp;quot; starting.&amp;quot;); &lt;br /&gt;
    do { &lt;br /&gt;
      count++; &lt;br /&gt;
 &lt;br /&gt;
      if(currentName != thrd.Name) { &lt;br /&gt;
        currentName = thrd.Name; &lt;br /&gt;
        Console.WriteLine(&amp;quot;In &amp;quot; + currentName); &lt;br /&gt;
      } &lt;br /&gt;
 &lt;br /&gt;
    } while(stop == false &amp;amp;&amp;amp; count &amp;lt; 1000000000); &lt;br /&gt;
    stop = true; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(thrd.Name + &amp;quot; terminating.&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class PriorityDemo { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    MyThread mt1 = new MyThread(&amp;quot;High Priority&amp;quot;); &lt;br /&gt;
    MyThread mt2 = new MyThread(&amp;quot;Low Priority&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    // Set the priorities. &lt;br /&gt;
    mt1.thrd.Priority = ThreadPriority.AboveNormal; &lt;br /&gt;
    mt2.thrd.Priority = ThreadPriority.BelowNormal; &lt;br /&gt;
 &lt;br /&gt;
    // Start the threads. &lt;br /&gt;
    mt1.thrd.Start(); &lt;br /&gt;
    mt2.thrd.Start(); &lt;br /&gt;
 &lt;br /&gt;
    mt1.thrd.Join(); &lt;br /&gt;
    mt2.thrd.Join(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
    Console.WriteLine(mt1.thrd.Name + &amp;quot; thread counted to &amp;quot; + &lt;br /&gt;
                      mt1.count); &lt;br /&gt;
    Console.WriteLine(mt2.thrd.Name + &amp;quot; thread counted to &amp;quot; + &lt;br /&gt;
                      mt2.count); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates the ThreadState property==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example14_3.cs illustrates the ThreadState property&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class Example14_3 &lt;br /&gt;
{&lt;br /&gt;
  // the Countdown method counts down from 10 to 1&lt;br /&gt;
  public static void Countdown() &lt;br /&gt;
  {&lt;br /&gt;
    for (int counter = 10; counter &amp;gt; 0; counter--) &lt;br /&gt;
    {&lt;br /&gt;
      Console.Write(counter.ToString() + &amp;quot; &amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    Console.WriteLine();&lt;br /&gt;
  }&lt;br /&gt;
  // the DumpThreadState method displays the current Thread&amp;quot;s state&lt;br /&gt;
  // Note that ThreadState is a bitmask, and multiple states for the&lt;br /&gt;
  // same thread are valid&lt;br /&gt;
  public static void DumpThreadState (&lt;br /&gt;
    Thread t&lt;br /&gt;
    ) &lt;br /&gt;
  {&lt;br /&gt;
    Console.Write(&amp;quot;Current state: &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.Aborted) == ThreadState.Aborted)&lt;br /&gt;
      Console.Write(&amp;quot;Aborted &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.AbortRequested) == &lt;br /&gt;
     ThreadState.AbortRequested)&lt;br /&gt;
      Console.Write(&amp;quot;AbortRequested &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.Background) == &lt;br /&gt;
     ThreadState.Background)&lt;br /&gt;
      Console.Write(&amp;quot;Background &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; &lt;br /&gt;
     (ThreadState.Stopped | ThreadState.Unstarted | &lt;br /&gt;
     ThreadState.Aborted)) == 0)&lt;br /&gt;
      Console.Write(&amp;quot;Running &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.Stopped) == ThreadState.Stopped)&lt;br /&gt;
      Console.Write(&amp;quot;Stopped &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.StopRequested) == &lt;br /&gt;
     ThreadState.StopRequested)&lt;br /&gt;
      Console.Write(&amp;quot;StopRequested &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.Suspended) == &lt;br /&gt;
     ThreadState.Suspended)&lt;br /&gt;
      Console.Write(&amp;quot;Suspended &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.SuspendRequested) == &lt;br /&gt;
     ThreadState.SuspendRequested)&lt;br /&gt;
      Console.Write(&amp;quot;SuspendRequested &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.Unstarted) == &lt;br /&gt;
     ThreadState.Unstarted)&lt;br /&gt;
      Console.Write(&amp;quot;Unstarted &amp;quot;);&lt;br /&gt;
    if ((t.ThreadState &amp;amp; ThreadState.WaitSleepJoin) ==&lt;br /&gt;
     ThreadState.WaitSleepJoin)&lt;br /&gt;
      Console.Write(&amp;quot;WaitSleepJoin &amp;quot;);&lt;br /&gt;
    Console.WriteLine();&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    // create a second thread&lt;br /&gt;
    Thread t2 = new Thread(new ThreadStart(Countdown));&lt;br /&gt;
    DumpThreadState(t2);&lt;br /&gt;
    // launch the second thread&lt;br /&gt;
    t2.Start();&lt;br /&gt;
    DumpThreadState(t2);&lt;br /&gt;
    // and meanwhile call the Countdown method from the first thread&lt;br /&gt;
    Countdown();&lt;br /&gt;
    // shut down the second thread&lt;br /&gt;
    t2.Abort();&lt;br /&gt;
    DumpThreadState(t2);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates the use of thread priorities==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example14_2.cs illustrates the use of thread priorities&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class Example14_2 &lt;br /&gt;
{&lt;br /&gt;
  // the Countdown method counts down from 1000 to 1&lt;br /&gt;
  public static void Countdown() &lt;br /&gt;
  {&lt;br /&gt;
    for (int counter = 1000; counter &amp;gt; 0; counter--) &lt;br /&gt;
    {&lt;br /&gt;
      Console.Write(counter.ToString() + &amp;quot; &amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    // create a second thread&lt;br /&gt;
    Thread t2 = new Thread(new ThreadStart(Countdown));&lt;br /&gt;
    // set the new thread to highest priority&lt;br /&gt;
    t2.Priority=ThreadPriority.Highest;&lt;br /&gt;
    // Locate the current thread and set it to the lowest priority&lt;br /&gt;
    Thread.CurrentThread.Priority=ThreadPriority.Lowest;&lt;br /&gt;
    // launch the second thread&lt;br /&gt;
    t2.Start();&lt;br /&gt;
    // and meanwhile call the Countdown method from the first thread&lt;br /&gt;
    Countdown();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use IsAlive to wait for threads to end==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
// Use IsAlive to wait for threads to end. &lt;br /&gt;
public class MoreThreads2 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Main thread starting.&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    // Construct three threads. &lt;br /&gt;
    MyThread mt1 = new MyThread(&amp;quot;Child #1&amp;quot;); &lt;br /&gt;
    MyThread mt2 = new MyThread(&amp;quot;Child #2&amp;quot;); &lt;br /&gt;
    MyThread mt3 = new MyThread(&amp;quot;Child #3&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    do { &lt;br /&gt;
      Console.Write(&amp;quot;.&amp;quot;); &lt;br /&gt;
      Thread.Sleep(100); &lt;br /&gt;
    } while (mt1.thrd.IsAlive &amp;amp;&amp;amp; &lt;br /&gt;
             mt2.thrd.IsAlive &amp;amp;&amp;amp; &lt;br /&gt;
             mt3.thrd.IsAlive); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Main thread ending.&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>