Lup
Lup

Reputation: 189

capture events from windows service

I built a Windows Service, let's call it Jobs. And I have a WinForm app, let's call it Viewer.

I want Viewer to receive events from Jobs when Jobs starts executing something so Viewer can display to the user that Job A started, did something, stopped, etc.

Is there a way to have Jobs throw events that Viewer can register to receive? The best solution I can think of is using MSMQ, however I'd like a more direct approach where I startup Viewer and it registers with the Jobs windows service and asks to receive notifications/events from it.

I can't seem to figure out how to get a Windows Service to Push something without using MSMQ, or to have others programs register with it to receive Pushes. I definitely do NOT want to use some weird file and/or database system where Viewer sleeps for 5 seconds and then checks for changes. I want something streamlined where Viewer Waits for Events, but does not have to use the MSMQ.

Upvotes: 1

Views: 94

Answers (1)

tom redfern
tom redfern

Reputation: 31750

You can use one of the WCF duplex bindings for this, such as netTcpBinding or dualHttpBinding. There is a full example here which would seem to do exactly what you want.

The drawback is that duplex is complex to understand and may not be that reliable. I would always implement a solution using one way communication (either via queueing or some other mechanism) if it was an option to do so. One way is always simpler and more reliable than duplex.

Upvotes: 1

Related Questions