<?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%2FCSharp_Tutorial%2FThread%2FLocalDataStoreSlot</id>
		<title>Csharp/CSharp Tutorial/Thread/LocalDataStoreSlot - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FThread%2FLocalDataStoreSlot"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Thread/LocalDataStoreSlot&amp;action=history"/>
		<updated>2026-04-29T22:37:08Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Thread/LocalDataStoreSlot&amp;diff=6664&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Thread/LocalDataStoreSlot&amp;diff=6664&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</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/CSharp_Tutorial/Thread/LocalDataStoreSlot&amp;diff=6665&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Thread/LocalDataStoreSlot&amp;diff=6665&amp;oldid=prev"/>
				<updated>2010-05-26T12:20:12Z</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;==Thread-local-storage: Named slots==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Runtime;&lt;br /&gt;
using System.Runtime.rupilerServices;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Thread.SetData(Thread.AllocateNamedDataSlot(&amp;quot;TestSlot&amp;quot;), 126);&lt;br /&gt;
        int slotValue2 = (int)Thread.GetData(Thread.GetNamedDataSlot(&amp;quot;TestSlot&amp;quot;));&lt;br /&gt;
        Console.WriteLine(slotValue2);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;126&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Thread-local-storage: Unnamed slots==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Runtime;&lt;br /&gt;
using System.Runtime.rupilerServices;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        LocalDataStoreSlot slot = Thread.AllocateDataSlot();&lt;br /&gt;
        Thread.SetData(slot, 63);&lt;br /&gt;
        int slotValue1 = (int)Thread.GetData(slot);&lt;br /&gt;
        Console.WriteLine(slotValue1);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;63&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Thread-static local-storage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Runtime;&lt;br /&gt;
using System.Runtime.rupilerServices;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    [ThreadStatic]&lt;br /&gt;
    private static string threadStaticData = &amp;quot;Empty&amp;quot;;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Thread[] threads = new Thread[3];&lt;br /&gt;
        for (int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;
        {&lt;br /&gt;
            threads[i] = new Thread(delegate(object j) {&lt;br /&gt;
                threadStaticData = &amp;quot;thread no: &amp;quot; + j;&lt;br /&gt;
                Console.WriteLine(&amp;quot;[Thread{0}] = {1}&amp;quot;, j, threadStaticData);&lt;br /&gt;
            });&lt;br /&gt;
            threads[i].Start(i);                &lt;br /&gt;
        }&lt;br /&gt;
        foreach (Thread t in threads)&lt;br /&gt;
            t.Join();&lt;br /&gt;
        Console.WriteLine(&amp;quot;[Master] after loop = {0}&amp;quot;, threadStaticData);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;[Thread0] = thread no: 0&lt;br /&gt;
[Thread1] = thread no: 1&lt;br /&gt;
[Thread2] = thread no: 2&lt;br /&gt;
[Master] after loop = Empty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use LocalDataStoreSlot==&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;
Book Accelerated C# 2005&lt;br /&gt;
    * By Trey Nash&lt;br /&gt;
    * ISBN: 1-59059-717-6&lt;br /&gt;
    * 432 pp.&lt;br /&gt;
    * Published: Aug 2006&lt;br /&gt;
    * Price: $39.99&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
public class MyClass&lt;br /&gt;
{&lt;br /&gt;
    static MyClass() {&lt;br /&gt;
        tlsSlot = Thread.AllocateDataSlot();&lt;br /&gt;
    }&lt;br /&gt;
    public MyClass() {&lt;br /&gt;
        Console.WriteLine( &amp;quot;Creating MyClass&amp;quot; );&lt;br /&gt;
    }&lt;br /&gt;
    public static MyClass MyThreadDataClass {&lt;br /&gt;
        get {&lt;br /&gt;
            Object obj = Thread.GetData( tlsSlot );&lt;br /&gt;
            if( obj == null ) {&lt;br /&gt;
                obj = new MyClass();&lt;br /&gt;
                Thread.SetData( tlsSlot, obj );&lt;br /&gt;
            }&lt;br /&gt;
            return (MyClass) obj;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private static LocalDataStoreSlot tlsSlot = null;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    private static void ThreadFunc() {&lt;br /&gt;
        Console.WriteLine( &amp;quot;Thread {0} starting...&amp;quot;,Thread.CurrentThread.GetHashCode() );&lt;br /&gt;
        Console.WriteLine( &amp;quot;tlsdata for this thread is \&amp;quot;{0}\&amp;quot;&amp;quot;, MyClass.MyThreadDataClass );&lt;br /&gt;
        Console.WriteLine( &amp;quot;Thread {0} exiting&amp;quot;, Thread.CurrentThread.GetHashCode() );&lt;br /&gt;
    }&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Thread thread1 = new Thread( new ThreadStart(ThreadFunc) );&lt;br /&gt;
        Thread thread2 = new Thread( new ThreadStart(ThreadFunc) );&lt;br /&gt;
        thread1.Start();&lt;br /&gt;
        thread2.Start();&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Thread 3 starting...&lt;br /&gt;
Creating MyClass&lt;br /&gt;
tlsdata for this thread is &amp;quot;MyClass&amp;quot;&lt;br /&gt;
Thread 3 exiting&lt;br /&gt;
Thread 4 starting...&lt;br /&gt;
Creating MyClass&lt;br /&gt;
tlsdata for this thread is &amp;quot;MyClass&amp;quot;&lt;br /&gt;
Thread 4 exiting&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use thread-local storage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void SetError() &lt;br /&gt;
  {&lt;br /&gt;
    Random r = new Random();&lt;br /&gt;
    Thread.SetData(Thread.GetNamedDataSlot(&amp;quot;Number&amp;quot;), r.Next(100));&lt;br /&gt;
    Thread.SetData(Thread.GetNamedDataSlot(&amp;quot;Name&amp;quot;) ,Thread.CurrentThread.Name);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Number = &amp;quot; + Thread.GetData(Thread.GetNamedDataSlot(&amp;quot;Number&amp;quot;)));&lt;br /&gt;
    Console.WriteLine(&amp;quot;Name = &amp;quot; + Thread.GetData(Thread.GetNamedDataSlot(&amp;quot;Name&amp;quot;)));&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Thread.AllocateNamedDataSlot(&amp;quot;Number&amp;quot;);&lt;br /&gt;
    Thread.AllocateNamedDataSlot(&amp;quot;Name&amp;quot;);&lt;br /&gt;
    Thread t2 = new Thread(new ThreadStart(SetError));&lt;br /&gt;
    t2.Name = &amp;quot;t2&amp;quot;;&lt;br /&gt;
    t2.Start();&lt;br /&gt;
    Thread t3 = new Thread(new ThreadStart(SetError));&lt;br /&gt;
    t3.Name = &amp;quot;t3&amp;quot;;&lt;br /&gt;
    t3.Start();&lt;br /&gt;
    Thread.FreeNamedDataSlot(&amp;quot;Number&amp;quot;);&lt;br /&gt;
    Thread.FreeNamedDataSlot(&amp;quot;Name&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Number = 81&lt;br /&gt;
Name = t2&lt;br /&gt;
Number = 81&lt;br /&gt;
Name = t3&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>