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();
}
}
}
c#线程顺序执行
转载上一篇:C#中判断某个值是否存在于枚举
下一篇:VS中单元测试用法

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C# 实例构建的执行顺序
先看看一般类的实例化构建顺序 无继承的情况 静态字段 静态构造方法 实例字段 实例构
C# 构造函数 派生类 字段 -
C#运算符执行顺序对照表
逻辑运算符,逻辑运算符原本有四种,但用于单元的“非”运算符排在了前面,所以这里面就只有&、^、
c# 开发语言 java 运算符 双目运算符 -
c#子线程执行完怎么通知主线程(转)回调方法 回调函数 网络请求 加载 主线程
-
C++ cout执行顺序
C++ cout执行顺序 问题描述是这样的:如果在cout中调用函数,同时这个函数中包含输出语句,那么会先输出哪一句? 仔细一看
C++ cout c++ 压栈 执行顺序