C#多线程编程实战1.2暂停线程(休眠)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
//暂停线程
namespace Recipe2
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(PrintNumbersWithDelay);
t.Start();
PrintNumbers();
Console.ReadKey();
}
static void PrintNumbers()
{
Console.WriteLine("Starting");
for (int i = 1; i < 10; i++)
{
Console.WriteLine(i);
}
}
static void PrintNumbersWithDelay()
{
Console.WriteLine("starting");
for (int i = 1; i < 10; i++)
{
//线程挂起的制定时间
Thread.Sleep(TimeSpan.FromSeconds(2));//线程处于休眠状态 会占用尽可能少的CPU时间
Console.WriteLine(i);
}
}
}
}
C#多线程编程实战1.2暂停线程(休眠)的更多相关文章
- C#多线程编程实战1.1创建线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- C#多线程编程实战1.7前台线程和后台线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- C#多线程编程实战1.5检测线程状态
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- C#多线程编程实战1.4终止线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- C#多线程编程实战1.3等待线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- C#多线程编程实战(二)
1.1 简介 为了防止一个应用程序控制CPU而导致其他应用程序和操作系统本身永远被挂起这一可能情况,操作系统不得不使用某种方式将物理计算分割为一些虚拟的进程,并给予每个执行程序一定量的计算能力.此外操 ...
- Java多线程编程实战指南(核心篇)读书笔记(五)
(尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76730459冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...
- Java多线程编程实战指南(核心篇)读书笔记(四)
(尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76690961冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...
- Java多线程编程实战指南(核心篇)读书笔记(三)
(尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76686044冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...
随机推荐
- MySQL存储过程中的3种循环,存储过程的基本语法,ORACLE与MYSQL的存储过程/函数的使用区别,退出存储过程方法
在MySQL存储过程的语句中有三个标准的循环方式:WHILE循环,LOOP循环以及REPEAT循环.还有一种非标准的循环方式:GOTO,不过这种循环方式最好别用,很容易引起程序的混乱,在这里就不错具体 ...
- 路边拾遗之其他模块(struct/csv/xlwt/smtp)
struct模块 最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的 ...
- activemq artemis安装运行及其在springboot中的使用
安装 创建broker 在springboot中的使用 依赖 配置 Producer Consumer Rest使用 安装 http://activemq.apache.org/artemis/dow ...
- Tuple、list的区别以及dict和set
元组(Tuple): 定义方法:使用小括号() 使用方法: count:可以统计某个元组段在整个元组中出现的次数 index:可以查询某个元组段在整个元组中的元组号 name_tuple = ('xi ...
- 使用K2时提示未能加载文件或程序集Microsoft.IdentityModel等
转:http://www.cnblogs.com/dannyli/archive/2012/10/15/2724931.html K2安装成功后,打开workspace管理流程时报错如下图: 未能加载 ...
- Mongo实战之数据空洞的最佳实践
问题背景: 某天,开发部的同事跑过来反映: mongodb数据文件太大,快把磁盘撑爆了!其中某个db占用最大(运营环境这个db的数据量其实很小) 分析: 开发环境有大量测试的增/删/改操作,而由于Mo ...
- python数据字典的操作
一.什么是字典? 字典是Python语言中唯一的映射类型. 映射类型对象里哈希值(键,key)和指向的对象(值,value)是一对多的的关系,通常被认为是可变的哈希表. 字典对象是可变的,它是一个容器 ...
- google/dense_hash_map
这个库使用时需要注意的地方: 1.在插入数据之前,需要先调用set_empty_key()设置一个空Key,Key的值可以为任意符合类型的.但请注意之后插入的Key不能和空Key相同,否则会abort ...
- 168. Excel Sheet Column Title 由数字返回excel的标题
[抄题]: Given a positive integer, return its corresponding column title as appear in an Excel sheet. F ...
- Ubuntu下配置Apache的Worker模式
其实Apache本身的并发能力是足够强大的,但是Ubuntu默认安装的是Prefork模式下的Apache.所以导致很多人后面盲目的去 安装lighttpd或者nginx一类替代软件.但是这类软件有一 ...