Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi,

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

I have created task like

C#
public void Start()
       {
           Task.Factory.StartNew(() => this.configurationManager.Start()).AddErrorHandler();
           Task.Factory.StartNew(() => this.pingManager.Start()).AddErrorHandler();
           Task.Factory.StartNew(() => this.dataSyncManager.Start()).AddErrorHandler();
       }
Posted
Comments
Mahindra Shambharkar 20-Jul-15 6:37am    
Have you tried
IsCompleted Property

https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.iscompleted(v=vs.110).aspx

or Status property
https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.status(v=vs.110).aspx

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900