pcajax 发表于 2013-1-26 15:40:19

《你不常用的c#之五》:Thread与ThreadPool的内存之战

<div class="postBody">Thread与ThreadPool使用的时候在内存里对象是如何分布的呢?
今天我们就从内存堆的角度分析下两者。
先上小白鼠代码:
<div style="padding-bottom: 0px;" class="wp_codebox"><div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->static void Main(string[] args)
        {
            for (int i = 0; i < 30; i++)
            {
                Thread t = new Thread(new ThreadStart(ThreadProc));
                t.Name = "Overred_" + i;
                t.Start();
            }
            Console.Read();
        }
        static void ThreadProc()
        {
            try
            {
                for (int i = 0; i < 10; i++)
                {
                     Console.WriteLine("{0}  Value:{1}",Thread.CurrentThread.Name,i);
                }
               
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
页: [1]
查看完整版本: 《你不常用的c#之五》:Thread与ThreadPool的内存之战