zoukankan      html  css  js  c++  java
  • c#线程顺序执行

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    namespace 线程同步
    {
        class Program
        {
            static int num = 1;
            static void Main(string[] args)
            {
                test2();        
            }

            //线程顺序执行方法1

            static void test1()
            {
                Action act = () =>
                {
                    num++;
                    Console.WriteLine(num);
                };



                Task.Factory.StartNew(act).ContinueWith(o => act()).ContinueWith(o=>act());

                Console.ReadLine();
            }


            //线程顺序执行方法2
            static void test2()
            {
                Action act = () =>
                {
                    Console.WriteLine("this is 1");
                
                };


                Action act2 = () =>
                {
                   
                    Console.WriteLine("this is 2");
                };


                Action act3 = () =>
                {
                    
                    Console.WriteLine("this is 3");
                };

                Thread t1 = new Thread(new ThreadStart(act));
                Thread t2 = new Thread(new ThreadStart(act2));
                Thread t3 = new Thread(new ThreadStart(act3));

                t1.Start();
                t2.Start();
                t2.Join(); //主线程停止,执行t2
                t3.Start();
                t3.Join(); //主线程停止,执行t3

                Console.ReadLine();
            }

        }




    }

  • 相关阅读:
    ThinkPHP5远程代码执行高危漏洞(附:升级修复解决方法)
    PowerDesigner 表格导出为excel
    ubuntu 18.04 配置远程ssh/远程ftp/远程vnc登陆
    Linux apache的运行用户和用户组
    mac系统 安装pip,用python读写excel(xlrd、xlwt)安装
    nvm 设置 nodejs 默认版本
    js基础
    Node.js 8 中的 util.promisify的详解
    HTTP协议中POST、GET、HEAD、PUT等请求方法以及一些常见错误
    MQTT简介
  • 原文地址:https://www.cnblogs.com/tiancai/p/6904178.html
Copyright © 2011-2022 走看看