Hi,
Change your partial class name and its constructor name, because the nae of the main class and partial class cannot be same. Try this:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
namespace MyFirstWindowsService
{
public class MyFirstWindowsService
{
static void Main()
{
ServiceBase[] ServicesToRun;
Debugger.Break();
ServicesToRun = new ServiceBase[]
{
new Test()
};
ServiceBase.Run(ServicesToRun);
}
public partial class Test : ServiceBase
{
public Test()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
timer.Enabled = true;
timer.Interval = 10000;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
protected override void OnStop()
{
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
System.Timers.Timer timer = new System.Timers.Timer();
public void MyFirstWindowsService()
{
InitializeComponent();
this.CanStop = true;
this.CanPauseAndContinue = true;
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
}
protected void timer_Elapsed(object source, System.Timers.ElapsedEventArgs aa)
{
System.Console.WriteLine("myTimer event occurred");
}
}
}
}
All the best.
-=-Amit