如何在调用window服务的stop()方法之前确保所有正在运行的Task都已完成。 [英] How to insure that all running Task is complete before calling stop() method of window service.

查看:91
本文介绍了如何在调用window服务的stop()方法之前确保所有正在运行的Task都已完成。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何确保在调用dispose服务方法之前完成所有异步任务。



我创建的任务类似





how to ensure that all asynchronous Task will be complete before calling dispose method of service.

I have created task like

public void Start()
       {
           Task.Factory.StartNew(() => this.configurationManager.Start()).AddErrorHandler();
           Task.Factory.StartNew(() => this.pingManager.Start()).AddErrorHandler();
           Task.Factory.StartNew(() => this.dataSyncManager.Start()).AddErrorHandler();
       }

推荐答案

回答你的问题(通过谷歌搜索你的问题花了大约5秒钟) https://msdn.microsoft.com/en-us/library/dd537610(v = vs.110).aspx [ ^ ]



但是你使用服务的方式是错误的。一个服务被设计为持续运行,你不会停止并启动它作为一种使其工作的方式,而是它需要暴露某种接口,或者有一些方法允许客户端与它通信告诉它工作,例如它可以侦听TCP端口,查看文件目录,轮询数据库,等待MSMQ消息等。
To answer your question (this took me approximately 5 seconds to find by googling your question) https://msdn.microsoft.com/en-us/library/dd537610(v=vs.110).aspx[^]

However the way you are using services is wrong. A service is designed to be constantly running, you don't stop and start it as a way of making it work, instead it needs to expose some kind of interface, or have some way of allowing clients to communicate with it to tell it to "do work", eg it can listen on a TCP port, watch a file directory, poll a database, wait for an MSMQ message etc.


这篇关于如何在调用window服务的stop()方法之前确保所有正在运行的Task都已完成。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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