zoukankan      html  css  js  c++  java
  • C#多线程编程实战1.7前台线程和后台线程

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    //前台线程和后台线程
    namespace Recipe7
    {
    class Program
    {
    static void Main(string[] args)
    {
    var sampleForeground=new ThreadSample(10);
    var sampleBackground=new ThreadSample(20);

    var threadOne = new Thread(sampleForeground.CountNumbers);
    threadOne.Name = "ForegroundThread";
    var threadTwo = new Thread(sampleBackground.CountNumbers);
    threadTwo.Name = "BackgroundThread";
    threadTwo.IsBackground = true;

    threadOne.Start();
    threadTwo.Start();

    Console.ReadKey();
    }
    }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    namespace Recipe7
    {
    public class ThreadSample
    {
    private readonly int _iterations;
    public ThreadSample(int iterations)
    {
    _iterations = iterations;
    }
    public void CountNumbers()
    {
    for (int i = 0; i < _iterations; i++)
    {
    Thread.Sleep(TimeSpan.FromMilliseconds(500));
    Console.WriteLine("currentThread.Name:{0} prints{1}",Thread.CurrentThread.Name,i);
    }
    }
    }
    }

  • 相关阅读:
    vanilla单词的意思
    快速排序实现
    python下载一些包出现time out的问题解决
    神经网络浅讲:从神经网络到深度学习
    神经网络基础知识
    TCP/IP
    查找机器学习相关数据集
    [数据治理]
    【算法】——LRU
    【大数据开发工程师】面试——HBase
  • 原文地址:https://www.cnblogs.com/tsh292278/p/9238212.html
Copyright © 2011-2022 走看看