一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net中C#获取线程编号实例程序

时间:2014-08-30 编辑:简简单单 来源:一聚教程网

有时我们需要确定应用程序是否启用了多线程,此时可以通过获取线程编号进行判断(Thread.Name属性值常为空不能用于判断):

 代码如下 复制代码

using System;
using System.Threading;

namespace ConsoleApplication1
{
    public class Program
    {      
        static public void Main(string[] args)
        {
            Console.WriteLine("MainThreadId:" + Thread.CurrentThread.ManagedThreadId);

            Action test = Test;
            test.BeginInvoke("mzwu.com", TestCallback, test);

            Console.ReadKey();
        }

        static void Test(string str)
        {
            Console.WriteLine("SubThreadId:" + Thread.CurrentThread.ManagedThreadId);
        }

        static void TestCallback(IAsyncResult ar)
        {
            Action handler = (Action)ar.AsyncState;
            handler.EndInvoke(ar);
        }
    }
}

asp.net中C#获取线程编号实例程序 

热门栏目