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("文件服务输出!");
                }
            }
        }
    }
  • 相关阅读:
    ubuntu install ssh server
    blug聚会&&小资早餐
    virtual box share folder usage
    关于xrdp的安装设置
    使用scp传送文件
    firefox插件集锦
    原来ubuntu早有关机功能
    blug聚会&&小资早餐
    加域工具
    ubuntu安装virtual box在命令行
  • 原文地址:https://www.cnblogs.com/csharponworking/p/1641596.html
Copyright © 2011-2022 走看看