Windows Service

  • Thread starter Thread starter junior lopes
  • Start date Start date
J

junior lopes

i have 2 applications, one is windows application, the other is windows
service.
the windows application must start and stop the windows service.
so i neeed to have, a setup that can install both at the same. the
windows application must start and stop the service.
is that possible ?
i have other question, when i desinstall the program can it stop the
service and desinstall the windows service and the windows application?
my purpose is to make a program, that uses windows service, controlled
by windows application.

Thanks for helping
 
windows application must start and stop the service.
//using System.ServiceProcess;
ServiceController controller = new ServiceController("MyService");
controller.Start(null);
controller.Stop();
i have other question, when i desinstall the program can it stop the
service and desinstall the windows service and the windows application?
No, by using installutil under .NET SDK it will only uninstall your
windows service.

HTH
Erick Sgarbi
www.blog.csharpbox.com
 
The setup program used to uninstall your application can also uninstall
your service. You will need to create a custom action and implement an
installer class to handle that.

Best Regards
Johann Blake
 
Your service should have a master thread running that waits to be
signalled by the Service Controll Manager to Stop. Here is an idea to
implement your functionality.

protected override void OnStart(string[] args) {
// TODO: Add code here to start your service.
// create our threadstart object to wrap our delegate
method
ThreadStart ts = new ThreadStart(this.ServiceMain);

// create the manual reset event and set it to an
initial state of unsignaled
m_shutdownEvent = new ManualResetEvent(false);

// create the worker thread
m_thread = new Thread(ts);

// go ahead and start the worker thread
m_thread.Start();

// call the base class so it has a chance to perform any
work it needs to
base.OnStart(args);

}

protected void ServiceMain() {
bool bSignaled = false;
int nReturnCode = 0;

while(true) {
// wait for the event to be signaled or
for the configured delay
bSignaled =
m_shutdownEvent.WaitOne(m_delay, true);

// if we were signaled to shutdow, exit
the loop
if(bSignaled == true)
break;

// let's do some work
nReturnCode = Execute();
}
}


This implementation will spawn a thread to run the ServiceMain function.
This function runs the infinite loop and pauses for the duration set in
m_delay to see if the SCM is telling the service to stop. The Execute
function will run on the interval set in m_delay. This is the same type
of functionality as the timer without the event overhead.


-----Original Message-----
From: junior lopes [mailto:[email protected]]
Posted At: Thursday, August 11, 2005 7:38 AM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Windows Service
Subject: Windows Service


i have 2 applications, one is windows application, the other is windows
service.
the windows application must start and stop the windows service.
so i neeed to have, a setup that can install both at the same. the
windows application must start and stop the service.
is that possible ?
i have other question, when i desinstall the program can it stop the
service and desinstall the windows service and the windows application?
my purpose is to make a program, that uses windows service, controlled
by windows application.

Thanks for helping
 
Back
Top