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

    using System;
    using System.Threading;

    namespace ConsoleApplication1
    {
        //class Program
        //{
        //    static void Main(string[] args)
        //    {
        //        Thread DepthChangedThread = new Thread(delegate() { Console.WriteLine("OK"); });
        //        DepthChangedThread.Name = "OK";
        //        Console.WriteLine(DepthChangedThread.Priority.ToString());
        //        DepthChangedThread.Abort();
        //        DepthChangedThread.Join();
        //        DepthChangedThread.Start();
        //    }
        //}

        class MainRun
        {

            static int interval = 700;
            static void Main()
            {
                Console.WriteLine("Interal to display results at?");
                interval = int.Parse(Console.ReadLine());

                Thread thisThread = Thread.CurrentThread;
                thisThread.Name = "Main Thread";

                //ThreadStart workerStart = new ThreadStart(StartMethod);
                Thread workerThread = new Thread(delegate() { StartMethod(); });
                workerThread.Name = "Worker";
                workerThread.Start();

                DisplayNumberThread();
                Console.WriteLine("Main Thread Finished!");

                Console.ReadLine();        
            }
            static void DisplayNumberThread()
            {
                Thread thisThead = Thread.CurrentThread;
                string name = thisThead.Name;
                Console.WriteLine("Startint thread:"+name);
                Console.WriteLine(name+":Current culture="+thisThead.CurrentCulture);
                //int interval=700;
                for (double i =1; i <=9*interval; i++)
                {
                    if(i%interval==0)
                        Console.WriteLine(name+":count has reahed."+i);
                   
                }
            }
            static void StartMethod()
            {
                DisplayNumberThread();
                Console.WriteLine("Worker Thread Finished!");
            }
        }
       
    } //输入一个数后,显示出这个数的几个倍数。注意里面的ThreadStart 那,如果不用这个可以使用匿名委托。Culture是区域的意思。

  • 相关阅读:
    学习笔记65—学位和学历区别
    学习笔记64—兴趣阅读之文学
    学习笔记63—兴趣阅读之法律
    学习笔记62—兴趣阅读之管理学
    学习笔记61—兴趣阅读之经济学
    学习笔记60—SPSS
    学习笔记59—收藏这7个在线配色神器,再也不愁配色灵感了
    学习笔记58—3D杯子设计
    网络处理2-异步POST请求和同步请求
    网络处理1-异步GET请求
  • 原文地址:https://www.cnblogs.com/fat_li/p/1837467.html
Copyright © 2011-2022 走看看