|
-
December 8th, 2004, 10:34 AM
#1
Windows services with C#
I found some articles that describe how to create windows services with VB.Net. Is there any that shows how to do it with C#??
Thank you
-
December 8th, 2004, 11:10 AM
#2
Re: Windows services with C#
You should be able to translate the VB.NET code into C# easily enough.
If not, here's a little snippet I wrote ages back to test services :
Code:
using System;
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
class UserService : System.ServiceProcess.ServiceBase
{
public UserService()
{
this.AutoLog = true;
this.CanStop = true;
this.CanPauseAndContinue = false;
this.ServiceName = "TestService";
}
protected override void OnStart(string [] args)
{
}
protected override void OnStop()
{
}
}
class App
{
[STAThread]
static public void Main()
{
System.ServiceProcess.ServiceBase.Run(new UserService());
}
}
[RunInstallerAttribute(true)]
public class UserServiceInstaller : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public UserServiceInstaller()
{
serviceInstaller = new ServiceInstaller();
processInstaller = new ServiceProcessInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Manual;
serviceInstaller.ServiceName = "TestService";
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
Compile this up and run
Code:
InstallUtil <executable with '.exe'>
to install it into the services list, and
Code:
InstallUtil /u <executable with '.exe'>
to uninstall.
Darwen.
-
December 8th, 2004, 11:35 AM
#3
Re: Windows services with C#
Thanks again
You are very helpfull!
Wish you the best
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|