Windows Service for a long running task in .NET


We have a working web application to which we are planning to add a new functionality.
This is a long running task which takes at least 30 minutes or more.
We are thinking a windows service may help us but we are not sure. I have a few questions as listed below

So, this is how it should work:

From the web application users will login and select a date, start time and end time and hit a submit button.
These 3 should be passed as parameters to the windows service.
Based on these 3 parameters, windows service will connect to the database and process the data and finally update the database.


Can this be done in a windows service? Can we pass parameters to a windows service?
Within this windows service can we consume web services?
Right now, our web application and the database are on 2 different servers. Where should we install our windows service?

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Well that's kind of what I am saying:  In order to "call" the windows service, you will have to use some kind of inter-process communication. There is no way to call a remote application as if it were itself a function. You need to expose some mechanism for external processes to access your service. This is why I mentioned .NET remoting.

Now, if you instead wanted your service to call the WCF on some kind of timer, then that would be fairly straight-forward. You would simply "Add Service Reference" to your WCF service from within the Windows service project. Then you would simply need to set up a schedule for your Windows service to make the calls out to the WCF. You could use a timer for this scehduling.
käµfm³d 👽Commented:
Can this be done in a windows service?

Can we pass parameters to a windows service?
In a matter of speaking, yes. You will need some sort of inter-process communication (IPC).

Within this windows service can we consume web services?

Where should we install our windows service?
Whichever you one you prefer, and which makes the most sense. Your service will be a process unto itself, so it should affect neither the web server software nor the database software--assuming you have a beefy machine. If you're still running single-core/single-processor machines, then it's going to be a hit no matter where you put it.

You might see better performance if the service is on the database machine since the database will be right there, but then you have to deal with sending parameters across the wire to the service. I believe remoting can handle this; not sure about named pipes--shared memory is definitely out. If you put the service on the web server, then any of the IPC should work, and the connection classes that you use to interact with databases are already set up to connect to remote systems.
shahjagatAuthor Commented:

For this inter process communication, can i use WCF?
From WCF, how would i call the windows service?
shahjagatAuthor Commented:

correct me if i am wrong.

The way i was thinking was web application calls a method exposed by WCF service which inturn will call a method in windows service.

ASP.NET --> WCF Service method ---> Windows Service

Can this be done?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.