using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//检测线程状态
namespace Recipe5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("starting program");
Thread t1 = new Thread(PrintNumbersWithStatus);
Thread t2 = new Thread(DoNothing);
Console.WriteLine(t1.ThreadState.ToString());
t1.Start();
t2.Start();
for (int i = 1; i < 10; i++)
{
Console.WriteLine(t1.ThreadState.ToString());
}
Thread.Sleep(6);
t1.Abort();
Console.WriteLine("a thread has been aborted");
Console.WriteLine(t1.ThreadState.ToString());
Console.WriteLine(t2.ThreadState.ToString());
Console.ReadKey();
}
static void DoNothing()
{
Thread.Sleep(2000);

}
static void PrintNumbersWithStatus()
{
Console.WriteLine("starting...");
Console.WriteLine(Thread.CurrentThread.ThreadState.ToString());
for (int i = 1; i < 10; i++)
{
Thread.Sleep(TimeSpan.FromSeconds(2));
Console.WriteLine(i);
}
}
}
}

C#多线程编程实战1.5检测线程状态的更多相关文章

  1. C#多线程编程实战1.1创建线程

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  2. C#多线程编程实战1.7前台线程和后台线程

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. C#多线程编程实战1.4终止线程

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  4. C#多线程编程实战1.3等待线程

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  5. C#多线程编程实战1.2暂停线程(休眠)

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. C#多线程编程实战(一):线程基础

    1.1 简介 为了防止一个应用程序控制CPU而导致其他应用程序和操作系统本身永远被挂起这一可能情况,操作系统不得不使用某种方式将物理计算分割为一些虚拟的进程,并给予每个执行程序一定量的计算能力.此外操 ...

  7. C#多线程编程实战(二)

    1.1 简介 为了防止一个应用程序控制CPU而导致其他应用程序和操作系统本身永远被挂起这一可能情况,操作系统不得不使用某种方式将物理计算分割为一些虚拟的进程,并给予每个执行程序一定量的计算能力.此外操 ...

  8. Java多线程编程实战指南(核心篇)读书笔记(四)

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76690961冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...

  9. Java多线程编程实战指南(核心篇)读书笔记(三)

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76686044冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...

随机推荐

  1. ITextSharp Table使用 (转)

    原文:http://www.cnblogs.com/LifelongLearning/archive/2011/05/16/2048116.html 表格是我们在制作文档时,经常使用的一个元素.对布局 ...

  2. 012. MVC5中Razor引擎使用模板页

    1.文件→新建项目→框架选择.NET Framework 4.5 2.确定后选择ASP.NET 4.5 模板→MVC→为以下项添加文件夹和核心引用→MVC, 在vs 2015中默认就使用的Razor引 ...

  3. Linux学习笔记 -- Shell 数组

    定义 在Shell的世界里,我们只能定义一维数组. 定义数组的时候不需要指定长度,数组的下标从0开始; Shell 数组用括号来表示,元素用"空格"符号分割开,语法格式如下: sh ...

  4. c语言相关知识点解析

    程序基本结构 常量变量标识符 数据类型 整型类型 浮点类型(实型) 基本类型转换 字符串 函数类型 枚举类型 enum 数组类型 结构体类型 共用体类型 字符串函数 运算符 流程控制语句 输入输出语句 ...

  5. ORACLE各版本下载地址

    ORACLE 10g下载|ORACLE 10g下载地址|ORACLE 10g官网下载地址 ORACLE 10g下载地址 oracle 下载还需要用户名我自己注册了个方便大家使用下载 user:1603 ...

  6. 06-Location详解之精准匹配

    之前nginx不是编译过吗?现在重新make install一下. 刚刚这个是我们新安装的.原始版的nginx,配置文件比较少,便于我们做调试. 试试精准匹配的概念. 匹配的是/.优先匹配这个最精准的 ...

  7. Linux 程序和进程的关系

    查看进程命令 ps  ps -elf|grep init|grep -v grep 查看init进程ID号:ps aux |grep init |grep -v grep; ps aux 会把系统所有 ...

  8. Opencv3 Mat对象构造函数与常用方法

    构造函数 Mat() Mat(int rows,int cols,int type) Mat(Size size,int type) Mat(int rows,int cols,int type,co ...

  9. PHP 5.5环境配置

    php5.5 + apache2.4 安装配置 1 2 3 4 5 6 7 分步阅读 php5.5 做了大量的更新,在与apache搭配的时候如何选择也很有讲究,这里我们以64位 php5.6 和 A ...

  10. 性能优化之_android布局优化

    优化布局的的原则就是减少创建的对象的数量,setContentView话费onCreate到onResume中的大概99%的时间1.使用Relativelayout而不是LinearLayout,Li ...