help on Windows Service ?

G

Guest

Dear all,

I have a process named P1 ( windows form or console app) which need to send
a command to a windows service and then my servcie will proceed that command
and do proper opertaion.

For instance P1 could send DATAREADY, my service shoulld receive that
command and handle it.

What is the way for my service to register to that command ?
Does P1 can geenrate an event that my servcie will register ? how ?

Thnaks for help
regards
serge
 
M

Mr. Arnold

calderara said:
Dear all,

I have a process named P1 ( windows form or console app) which need to
send
a command to a windows service and then my servcie will proceed that
command
and do proper opertaion.

For instance P1 could send DATAREADY, my service shoulld receive that
command and handle it.

What is the way for my service to register to that command ?
Does P1 can geenrate an event that my servcie will register ? how ?


You simply do this.

1) In your windows form or console application, you instantiate a Service
Controller that communicates with the Service.

ServiceController sc = new ServiceController("the service");
sc.Execute(201);

Just like there is a Onstop, Onstart, etc, etc event in a Service
application, there is a OnCustomCommand event.


2) In the Service application, you setup a OnCustomCommand event.

protected override void OnCustomCommand (int command)
{
if (command == 201)
Help();
else if (command == 200)
Help1();
}

I guess you can pass a string to the event, but I have only used an integer.

You can look it up use Google.
 
G

Guest

Thnaks arnold.
I have seen that already but coulsd find the link where I found it once..

regards
serge
 

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