<?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_Pool</id>
		<title>Csharp/C Sharp/Thread/Thread Pool - История изменений</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_Pool"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Pool&amp;action=history"/>
		<updated>2026-04-30T01:37:37Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Thread/Thread_Pool&amp;diff=1049&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_Pool&amp;diff=1049&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_Pool&amp;diff=1050&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_Pool&amp;diff=1050&amp;oldid=prev"/>
				<updated>2010-05-26T11:42:51Z</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;==illustrates the use of the system thread pool==&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_12.cs illustrates the use of the system thread pool&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class Example14_12 &lt;br /&gt;
{&lt;br /&gt;
  // the Countdown method counts down from 1000 to 1&lt;br /&gt;
  public static void Countdown(Object o) &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;
    // ask the system to create and launch a second thread&lt;br /&gt;
    ThreadPool.QueueUserWorkItem(new WaitCallback(Countdown), null);&lt;br /&gt;
    // and meanwhile call the Countdown method from the first thread&lt;br /&gt;
    Countdown(null);&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;
==Thread pool demo==&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# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 * Version: 1&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace Client.Chapter_15___Threading&lt;br /&gt;
{&lt;br /&gt;
  public class MyMainClassChapter_15___Threading&lt;br /&gt;
  {&lt;br /&gt;
    public static ManualResetEvent MyManualEvent = new ManualResetEvent(false);&lt;br /&gt;
    public static AutoResetEvent MyAutoEvent = new AutoResetEvent(false);&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      ThreadPool.QueueUserWorkItem(new WaitCallback(DoBackgroundWorkManual));&lt;br /&gt;
      MyManualEvent.WaitOne();&lt;br /&gt;
      MyManualEvent.Reset();  //Sets the Event back to nonsignaled&lt;br /&gt;
      ThreadPool.QueueUserWorkItem(new WaitCallback(DoBackgroundWorkAuto));&lt;br /&gt;
      MyAutoEvent.WaitOne();&lt;br /&gt;
    }&lt;br /&gt;
    public static void DoBackgroundWorkManual(Object state)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Thread 1&amp;quot;);&lt;br /&gt;
      //Do stuff &lt;br /&gt;
      //Then release control back to the main thread&lt;br /&gt;
      MyManualEvent.Set(); //Signals the event&lt;br /&gt;
    }&lt;br /&gt;
    public static void DoBackgroundWorkAuto(Object state)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Thread 1&amp;quot;);&lt;br /&gt;
      //Do stuff &lt;br /&gt;
      MyAutoEvent.Set();&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;
==ThreadPool.QueueUserWorkItem==&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;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
class WinterLocked {&lt;br /&gt;
    public ManualResetEvent a = new ManualResetEvent(false);&lt;br /&gt;
    private int i = 5;&lt;br /&gt;
    public void Run(object s) {&lt;br /&gt;
        Interlocked.Increment(ref i);&lt;br /&gt;
        Console.WriteLine(&amp;quot;{0} {1}&amp;quot;,&lt;br /&gt;
                          Thread.CurrentThread.GetHashCode(), i);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class MainApp {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        ManualResetEvent mR = new ManualResetEvent(false);&lt;br /&gt;
        WinterLocked wL = new WinterLocked();&lt;br /&gt;
        for (int i = 1; i &amp;lt;= 10; i++) {&lt;br /&gt;
            ThreadPool.QueueUserWorkItem(new WaitCallback(wL.Run), 1);&lt;br /&gt;
        }&lt;br /&gt;
        mR.WaitOne(10000, true);&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;
==ThreadPool.RegisterWaitForSingleObject==&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.Threading;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    private static void EventHandler(object state, bool timedout)&lt;br /&gt;
    {&lt;br /&gt;
        if (timedout)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;{0} : Wait timed out.&amp;quot;, DateTime.Now.ToString(&amp;quot;HH:mm:ss.ffff&amp;quot;));&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;{0} : {1}&amp;quot;, DateTime.Now.ToString(&amp;quot;HH:mm:ss.ffff&amp;quot;), state);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        AutoResetEvent autoEvent = new AutoResetEvent(false);&lt;br /&gt;
        string state = &amp;quot;AutoResetEvent signaled.&amp;quot;;&lt;br /&gt;
        RegisteredWaitHandle handle = ThreadPool.RegisterWaitForSingleObject(autoEvent, EventHandler, state, 3000, false);&lt;br /&gt;
        while (Console.ReadLine().ToUpper() != &amp;quot;CANCEL&amp;quot;)&lt;br /&gt;
        {&lt;br /&gt;
            autoEvent.Set();&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Unregistering wait operation.&amp;quot;);&lt;br /&gt;
        handle.Unregister(null);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread Pool Sample==&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;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class ThreadPoolSample&lt;br /&gt;
{&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      ThreadPoolSample tps = new ThreadPoolSample();&lt;br /&gt;
   }&lt;br /&gt;
   public ThreadPoolSample()&lt;br /&gt;
   {&lt;br /&gt;
      int i;&lt;br /&gt;
      ThreadPool.QueueUserWorkItem(new WaitCallback(Counter));&lt;br /&gt;
      ThreadPool.QueueUserWorkItem(new WaitCallback(Counter2));&lt;br /&gt;
      for(i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;main: {0}&amp;quot;, i);&lt;br /&gt;
         Thread.Sleep(1000);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   void Counter(object state)&lt;br /&gt;
   {&lt;br /&gt;
      int i;&lt;br /&gt;
      for (i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;  thread: {0}&amp;quot;, i);&lt;br /&gt;
         Thread.Sleep(2000);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   void Counter2(object state)&lt;br /&gt;
   {&lt;br /&gt;
      int i;&lt;br /&gt;
      for (i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;    thread2: {0}&amp;quot;, i);&lt;br /&gt;
         Thread.Sleep(3000);&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;
==Thread Pool Tcp Server==&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# Network Programming &lt;br /&gt;
by Richard Blum&lt;br /&gt;
Publisher: Sybex &lt;br /&gt;
ISBN: 0782141765&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class ThreadPoolTcpSrvr&lt;br /&gt;
{&lt;br /&gt;
   private TcpListener client;&lt;br /&gt;
   public ThreadPoolTcpSrvr()&lt;br /&gt;
   {&lt;br /&gt;
      client = new TcpListener(9050);&lt;br /&gt;
      client.Start();&lt;br /&gt;
      Console.WriteLine(&amp;quot;Waiting for clients...&amp;quot;);&lt;br /&gt;
      while(true)&lt;br /&gt;
      {&lt;br /&gt;
         while (!client.Pending())&lt;br /&gt;
         {&lt;br /&gt;
            Thread.Sleep(1000);&lt;br /&gt;
         }&lt;br /&gt;
         ConnectionThread newconnection = new ConnectionThread();&lt;br /&gt;
         newconnection.threadListener = this.client;&lt;br /&gt;
         ThreadPool.QueueUserWorkItem(new&lt;br /&gt;
                    WaitCallback(newconnection.HandleConnection));&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      ThreadPoolTcpSrvr tpts = new ThreadPoolTcpSrvr();&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
class ConnectionThread&lt;br /&gt;
{&lt;br /&gt;
   public TcpListener threadListener;&lt;br /&gt;
   private static int connections = 0;&lt;br /&gt;
   public void HandleConnection(object state)&lt;br /&gt;
   {&lt;br /&gt;
      int recv;&lt;br /&gt;
      byte[] data = new byte[1024];&lt;br /&gt;
      TcpClient client = threadListener.AcceptTcpClient();&lt;br /&gt;
      NetworkStream ns = client.GetStream();&lt;br /&gt;
      connections++;&lt;br /&gt;
      Console.WriteLine(&amp;quot;New client accepted: {0} active connections&amp;quot;,&lt;br /&gt;
                         connections);&lt;br /&gt;
      string welcome = &amp;quot;Welcome to my test server&amp;quot;;&lt;br /&gt;
      data = Encoding.ASCII.GetBytes(welcome);&lt;br /&gt;
      ns.Write(data, 0, data.Length);&lt;br /&gt;
      while(true)&lt;br /&gt;
      {&lt;br /&gt;
         data = new byte[1024];&lt;br /&gt;
         recv = ns.Read(data, 0, data.Length);&lt;br /&gt;
         if (recv == 0)&lt;br /&gt;
            break;&lt;br /&gt;
      &lt;br /&gt;
         ns.Write(data, 0, recv);&lt;br /&gt;
      }&lt;br /&gt;
      ns.Close();&lt;br /&gt;
      client.Close();&lt;br /&gt;
      connections--;&lt;br /&gt;
      Console.WriteLine(&amp;quot;Client disconnected: {0} active connections&amp;quot;,&lt;br /&gt;
                         connections);&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>