Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between Windows Service and Desktop Application

I know that similar questions have been asked before, but even after all my Googling I'm still completely lost.

I've written a small Windows Service that does what my main application used to do in a background thread (it made sense to move it to a separate service for several reasons).

When the background thread was running as a part of my application it would fire an event every time it finished working (updating a database, in this case) and I would use a timestamp from that event to grab the appropriate information to update the window. I don't think the specifics are relevant, but please let me know if you need more details.

Now that I've got the database-filling stuff running as a service, the question becomes: How do I replace what used to be done by the event?

In other words, what's the simplest and/or most effective way to communicate a basic DateTime from my service to my app?

I've never done any IPC before but started reading up on it and got thoroughly confused. Named Pipes seem to be my best bet so far, but I've been unable to find anything that helps me understand their functionality... All I've found are poorly-commented chunks of code or "tutorials" that go way deeper than I need, without clearly covering the basics.

So, without being able to establish a good base, I'm a little stuck. What's the best method to implement simple communication that does what my event used to do and where can I learn the basics of that method?

EDIT:

As always, everyone here rocks, thanks for all the quick responses. Gerrie's link turned out to be exactly what I needed (though I didn't know that's what I needed at the time).

like image 375
Kyle G. Avatar asked Aug 30 '13 14:08

Kyle G.


People also ask

Can a Windows service launch an application?

Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop.

What is the difference between Windows service and console application?

The key difference between a process running as an app versus as a service is that the service can operate entirely outside the normal association with a user and session. Thus services can run such that they start before any user logs in and can continue running after users log off.

Can a Windows service open a browser?

If you pass the url as execution argument to your service executable then you can open it with the default browser using Process.

What are the benefits of Windows services?

Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface.


1 Answers

Don't get scared away by the named pipes concept, WCF will take care of the nasty bits for you. You'll only have to do the configuration, it's simply another communication channel, instead of using HTTP for example. So you'll need to look into WCF.

Check out this tutorial.

like image 57
Gerrie Schenck Avatar answered Oct 17 '22 11:10

Gerrie Schenck