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是区域的意思。

  • 相关阅读:
    opengl学习
    同步、异步、多线程与事件型综述
    Javascript异步编程的4种方法
    ASP.NET(C#) GridView (编辑、删除、更新、取消)
    浅析五大ASP.NET数据控件
    用 Eclipse 开发 Android 应用程序
    [C# 网络编程系列]专题十:实现简单的邮件收发器
    [C# 网络编程系列]专题九:实现类似QQ的即时通信程序
    [C# 网络编程系列]专题七:UDP编程补充——UDP广播程序的实现
    [C# 网络编程系列]专题六:UDP编程
  • 原文地址:https://www.cnblogs.com/fat_li/p/1837467.html
Copyright © 2011-2022 走看看