windows services

  • Thread starter Thread starter Gav
  • Start date Start date
G

Gav

Hi All,

Just starting to look at writing windows services if you stop the service
and build the project, do I have to run the installutil again or can I just
start the service again?

Thanks
Gav
 
You can just build the project again and start the service again. When
the service shuts down it blows away the process that was hosting your
service assemblies and thus releases the locks on them and their
resources. At least this has been my experience with the services that
I've built.

Have A Better One!

John M Deal, MCP
Necessity Software
 
You can just build the project again and start the service again.
When the service shuts down it blows away the process that was hosting
your service assemblies and thus releases the locks on them and their
resources. At least this has been my experience with the services
that I've built.

It works really well when you can use pre- and post- build events to start
and stop your service! One small thing to be aware of though - if the
service isn't running and your pre-build stops it, it will error out unless
you include an 'exit 0' to clear the errors in your pre-build event.

Also one other thing to be aware of... if your services is using remoting
w/ Singleton objects, the remoting infrastructure may still hold a
reference to your object for a while, so you may not be able to recompile
for a minute or so after your service exits. I haven't found a way around
this yet, so if anyone has an idea, let me know...

-mdb
 
Gav said:
Hi All,

Just starting to look at writing windows services if you stop the service
and build the project, do I have to run the installutil again or can I
just start the service again?


You can just restart the service.

But do yourself a favor. Switch the service project from a windows program
to a Console program and add something like this to the top of your static
void Main

// The main entry point for the process
static void Main(string[] args)
{
if (System.Diagnostics.Debugger.IsAttached || (args.Length > 0 &&
args[0].ToLower() == "/c"))
{
Console.WriteLine("Running in Console Mode");
Service1 svc = new Service1();
svc.OnStart(args);
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite );
return;
}

. . .


That way you can just hit F5 do debug the service and you can run it in a
console window by running

MyService /c

David
 
Thanks for the quick reply
Gav

David Browne said:
Gav said:
Hi All,

Just starting to look at writing windows services if you stop the service
and build the project, do I have to run the installutil again or can I
just start the service again?


You can just restart the service.

But do yourself a favor. Switch the service project from a windows
program to a Console program and add something like this to the top of
your static void Main

// The main entry point for the process
static void Main(string[] args)
{
if (System.Diagnostics.Debugger.IsAttached || (args.Length > 0 &&
args[0].ToLower() == "/c"))
{
Console.WriteLine("Running in Console Mode");
Service1 svc = new Service1();
svc.OnStart(args);
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite );
return;
}

. . .


That way you can just hit F5 do debug the service and you can run it in a
console window by running

MyService /c

David
 
Back
Top