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. }  
  • 相关阅读:
    《精通情绪》读书笔记
    绩效评估与绩效反馈
    数据分析报告格式zz
    学会谈判zz
    javascript中的双向绑定
    理解 DocumentFragment
    理解Object.defineProperty()
    Vue 改变数组中对象的属性不重新渲染View的解决方案
    ES6中Object.assign() 方法
    控制input输入框光标的位置
  • 原文地址:https://www.cnblogs.com/hsapphire/p/1978524.html
Copyright © 2011-2022 走看看