How to send events to a Window Service

U

Usman

Hi

I have a window service written in C#. I have another application that
requires a lengthy process to be performed like taking backup. How can I
make this lengthy process be performed by window service in such a manner
that my application may invoke the process. Is there any way that I can call
some method written in window service apart from Start, Stop, Pause etc from
my application or firing some custom event to the window service to start
that operation. Its better if I could get some mechanism to call the
service's method as I also need to pass some arguments from my application
to the service that may not be easy to send using event based calls. Please
advice.

Regards

Usman
 
P

Phil Wilson

ServiceController.ExecuteCommand lets your app send a one-way integer value
to your Service, which gets it in an OnCustomCommand event. You'll have to
use something like the registry to indicate back to the app that you've
finished.
 
A

adebaene

Usman said:
Hi

I have a window service written in C#. I have another application that
requires a lengthy process to be performed like taking backup. How can I
make this lengthy process be performed by window service in such a manner
that my application may invoke the process. Is there any way that I can call
some method written in window service apart from Start, Stop, Pause etc from
my application or firing some custom event to the window service to start
that operation. Its better if I could get some mechanism to call the
service's method as I also need to pass some arguments from my application
to the service that may not be easy to send using event based calls. Please
advice.

You can use whatever IPC mechanism you like to send commands from a
user mode app to the service :
- COM
- socket
- Named Pipe
- Event / MMF
- .NET remoting
- etc...

Arnaud
MVP - VC
 
U

Usman

Hi

You mentioned COM as a possibility. Is there any mechanism through which I
could expose the methods of window service like a com does and call it using
the exact signature of that exposed method from my application including the
parameters. Also how can the .Net Remoting be usefull in this scenario, can
a .Net remoting service expose methods of its own or are you referring to
the Remotable objects.

Regards

Usman Jamil
 
R

Richard Grimes

Usman said:
You mentioned COM as a possibility. Is there any mechanism through
which I
could expose the methods of window service like a com does and call it
using
the exact signature of that exposed method from my application
including the
parameters.

You cannot write a COM local server (exe) in .NET. The nearest
equivalent is to write a library assemly with public types and these
types will use some IPC (sockets or .NET remoting) to talk to the
equivalent types implemented in the service. The library assembly can
then be called via COM interop as an inproc server. (using the tlbexp
tool)
Also how can the .Net Remoting be usefull in this scenario, can
a .Net remoting service expose methods of its own or are you referring
to
the Remotable objects.

..NET remoting is an interprocess communication mechanism - it allows two
processes to talk with each other and it requires .NET in both the
client and server. In your case, the service provides the remote
objects. The client accesses these remote objects as if they are local
objects.

Richard
 
A

Arnaud Debaene

Usman said:
Hi

You mentioned COM as a possibility. Is there any mechanism through
which I could expose the methods of window service like a com does
and call it using the exact signature of that exposed method from my
application including the parameters. Also how can the .Net Remoting
be usefull in this scenario, can a .Net remoting service expose
methods of its own or are you referring to the Remotable objects.

Both COM and .NET remoting (and Corba too) are mechanisms to expose an
object so that it can be called upon by external programs (even programs on
another machine). The idea is that the service exposes on such object that
can be manipulated by external programs (in your case, the user app). You
can expose whatever functionnality you want through this object. The ser app
will call methods on the object exactly as if it was a local object.

Arnaud
MVP - VC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top