I have compilled a service in Visual C# 2010. If I click on BService.exe it starts but also show a messagebox: "Cannot start service from the command line or a debugger. A Windows Service must be installed (using installutil.exe) and then started with ServerExplorer, Windows Services Administrative tool or the NET START command." if I click OK program closes. If I install if with C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\installutil.exe, and start from services.msc it also starts but doesn't show MessageBox.Show("sdas"), so doesn't work. How to install/run the service?
public partial class BService : ServiceBase
{
private System.Timers.Timer timer;
public BService()
{
timer = new System.Timers.Timer(2000);
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
InitializeComponent();
}
public void Start() { timer.Start();}
public void Stop() { timer.Stop();}
protected override void OnStart(string[] args) { this.Start();}
protected override void OnStop() { this.Stop();}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("sdas");
}
}