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

    1. using System;   
    2. using System.Collections.Generic;   
    3. using System.Text;   
    4. using System.Threading;   
    5. namespace 线程练习   
    6. {   
    7.     class Program   
    8.     {   
    9.         static void Main(string[] args)   
    10.         {   
    11.             Console.WriteLine("开始一个新的线程,名为次线程");   
    12.             Thread t = new Thread(new ThreadStart(ThreadProc));   
    13.             t.Start();   
    14.             for (int i = 0; i < 4; i++)   
    15.             {   
    16.                 Console.WriteLine("主线程:" + i);   
    17.                 Thread.Sleep(1000);   
    18.             }   
    19.             Console.WriteLine("调用Join函数等待次线程结束");   
    20.             //当次线程执行完毕后,Join阻塞调用线程,直到某个线程终止为止,本例为次线程   
    21.             t.Join();   
    22.             Console.WriteLine("线程执行完毕");   
    23.         }   
    24.         public static void ThreadProc()   
    25.         {   
    26.             for (int i = 0; i < 10; i++)   
    27.             {   
    28.                 Console.WriteLine("ThreadPorc:{0}", i);   
    29.                 Thread.Sleep(1000);//将当前进程阻塞指定的毫秒数   
    30.             }   
    31.   
    32.   
    33.         }   
    34.     }   
    35. }  
  • 相关阅读:
    Binary Tree Zigzag Level Order Traversal
    Binary Tree Level Order Traversal
    Symmetric Tree
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock
    Triangle
    Populating Next Right Pointers in Each Node II
    Pascal's Triangle II
    Pascal's Triangle
    Populating Next Right Pointers in Each Node
  • 原文地址:https://www.cnblogs.com/hsapphire/p/1978524.html
Copyright © 2011-2022 走看看