以编程方式启动和停止Web服务 [英] Start and stop web service programatically

查看:126
本文介绍了以编程方式启动和停止Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web服务名称是UF17DataDownloader,我开始创建对象

就像

 DataDownload = new UF17DataDownloader(); 





任何人都可以告诉我如何停止这项服务

解决方案

那么,你的srevice建立在哪个框架之上???

请在你的问题中尽可能地澄清!


  class 服务器
{
private volatile bool _isStopRequested = false ;
private TcpListener tcpListener;
private 线程listenThread;

public 服务器()
{
.tcpListener = new TcpListener(IPAddress.Any, 3000 );
.listenThread = 主题( new ThreadStart(ListenForClients));
}

public void Start()
{
this .listenThread.Start();
}

public void Stop(){
_isStopRequested = false ;
}


私有 void ListenForClients()
{
this .tcpListener.Start();

while (!_isStopRequested)
{
// 阻止,直到客户端连接到服务器
TcpClient client = .tcpListener。 AcceptTcpClient();

// 在您的工作流程中做一些事情....
}
}
}





i认为您将了解启动和停止服务的基本想法。


Web service name is UF17DataDownloader, am start starting this by creating object
like

DataDownload = new UF17DataDownloader();



can any one tell me how to stop this service

解决方案

Well, on top of which framework does your srevice was built???
Please, clarify as much as possible in your question!


class Server
  {
    private volatile bool _isStopRequested=false;
    private TcpListener tcpListener;
    private Thread listenThread;

    public Server()
    {
      this.tcpListener = new TcpListener(IPAddress.Any, 3000);
      this.listenThread = new Thread(new ThreadStart(ListenForClients));
    }

    public void Start()
    {
     this.listenThread.Start();
    }

public void Stop(){ 
_isStopRequested=false;
}


  private void ListenForClients()
  {
    this.tcpListener.Start();

    while (!_isStopRequested)
    {
      //blocks until a client has connected to the server
      TcpClient client = this.tcpListener.AcceptTcpClient();

      //do some stuff with your workflow....
    } 
  }
}



i think you will catch the basic idea of starting and stopping service.


这篇关于以编程方式启动和停止Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆