zoukankan      html  css  js  c++  java
  • C#多线程操作

    static void Main(string[] args)
            {
    
                Thread thread = Thread.CurrentThread;
                thread.Name = "Main Thread";
                string threadMessage = string.Format("Thread ID:{0}
        Current AppDomainId:{1}
        " +
                    "Current ContextId:{2}
        Thread Name:{3}
        " +
                    "Thread State:{4}
        Thread Priority:{5}
    ",
                    thread.ManagedThreadId, Thread.GetDomainID(), Thread.CurrentContext.ContextID,
                    thread.Name, thread.ThreadState, thread.Priority);
    
                Console.WriteLine(threadMessage);
                Console.WriteLine("Main threadId is:" + Thread.CurrentThread.ManagedThreadId);
                Message message = new Message();
                Thread thread1 = new Thread(new ThreadStart(message.ShowMessage));
                thread1.Start();
                Console.WriteLine("Do something ..........!");
                Console.WriteLine("Main thread working is complete!");
    
    
                Console.ReadKey();
            }

    新建Message类:

    class Message
        {
            public void ShowMessage()
            {
                string message = string.Format("Async threadId is :{0}",Thread.CurrentThread.ManagedThreadId);
                Console.WriteLine(message);
    
                for (int n = 0; n < 10; n++)
                {
                    Thread.Sleep(300);
                    Console.WriteLine("The number is:" + n.ToString());
                }
            }
        }

    结果为:

  • 相关阅读:
    Faster rcnn代码理解(2)
    Faster rcnn代码理解(1)
    BN讲解(转载)
    faster-rcnn
    编程修养
    人才盘点
    Source Insight 技巧总结
    使用DNSSCrypt解决DNS污染问题
    程序员的自我修养 学习笔记(5)
    闯红灯检测原理
  • 原文地址:https://www.cnblogs.com/jiangshuai52511/p/7889864.html
Copyright © 2011-2022 走看看