zoukankan      html  css  js  c++  java
  • C#多线程编程实战1.5检测线程状态

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

  • 相关阅读:
    查询论文引用次数及格式和相似论文的方法
    JAVA日期加减运算
    luogu2833 等式
    luogu2261 [CQOI2007] 余数之和
    luogu2822 组合数问题
    luogu3942 将军令 贪心
    luogu3941 入阵曲
    luogu3939 数颜色
    二分查找总结
    luogu3938 斐波那契
  • 原文地址:https://www.cnblogs.com/tsh292278/p/9238205.html
Copyright © 2011-2022 走看看