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();
            }

        }




    }

  • 相关阅读:
    【Robot Framework】List 的相关使用方法
    robot framework ——关键字run keyword if 如何在一个条件下接多个执行语句,以及如何写复杂条件句-关键字Run Keywords和and
    Robotframework之页面元素操作功能
    selenium之 下拉选择框Select
    selenium修改readonly属性的元件
    Robotframework之Python的自定义库
    python 元类详解
    从<<JavaScript权威指南>>抄下来的一个例子
    链接
    Python+selenium之获取文本值和下拉框选择数据
  • 原文地址:https://www.cnblogs.com/tiancai/p/6904178.html
Copyright © 2011-2022 走看看