views:

18

answers:

1

Hello, I have a .net Windows Service developed in C#. OnStart of the service I am calling a function that stores the serviceName,DateTime in a ServiceLog sql Table and returns the ServiceID(ID number from the table).

OnStop I want to update the same record with the StopDateTime.

I don't know how to store the ID number that is returned above.

Please help

A: 

Maybe I've misread what you're asking, but this might be what you're looking for(?):

If the ServiceBase class is the one that is getting the data onstart and updating it onstop, then just store the id on your ServiceBase class in a local variable. (unless you've got a helper/service class that does this retrieval and updating, in which case maybe thats the best place to put it)

for example

public class MyService : ServiceBase
{
 private int id;

 public override OnStart()
 {
   id = GetIdFOrProcess("someidentifier");
   .....
 }

 public override OnStop()
 {
  UpdateServiceStopTime(id);
  .....
 }
}
saret