zoukankan      html  css  js  c++  java
  • 线程服务的停止与启动

    自己写服务的话,有线程的启动与停止,所以写了简单的实现的代码。
    代码
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Thread.Stop
    {
        
    /// <summary>
        
    /// 文件服务
        
    /// </summary>
        public class FileService
        {
            
    private volatile bool isStop;
            
    private System.Threading.Thread fileThread = null;


            
    public FileService()
            { }

            
    /// <summary>
            
    /// 启动服务
            
    /// </summary>
            public void Start()
            {
                fileThread 
    = new System.Threading.Thread(new System.Threading.ThreadStart(TranslateFile));
                fileThread.Start();
            }

            
    /// <summary>
            
    /// 中止服务
            
    /// </summary>
            public void Stop()
            {
                isStop 
    = true;

                
    if (fileThread != null && fileThread.ThreadState == System.Threading.ThreadState.Running)
                    fileThread.Abort();
                fileThread 
    = null;
            }

            
    private void TranslateFile()
            {
                
    while (!isStop)
                {
                    
    //模拟长时间操作
                    Console.WriteLine("文件服务输出!");
                }
            }
        }
    }
  • 相关阅读:
    AVFrame 解析
    Mat与图像的基本概念
    linux基本操作
    Makefile 使用
    MySQL的安装与配置——详细过程
    k8s imagePullPolicy拉取策略
    K8S拉取Django项目创建pod
    Harbor单点仓库部署
    Django项目构建发布Harbor仓库
    K8S集群部署-二进制部署
  • 原文地址:https://www.cnblogs.com/csharponworking/p/1641596.html
Copyright © 2011-2022 走看看