I have a created a windows service and created installer for it. It is installed and started but the code i have written inside it is not executing. actually when i start the service from the service window the OnStart() function is not fired. nor the initializecomponent() nor the static void main function.. can any one help me with it
please guide me where i have done wrong.
here are some code lines. let me know if u want more of what i have written
public partial class iMArchiveService : ServiceBase
{
Boolean isArchiving = false;
public iMArchiveService()
{
MyException.CreateLog("iMArchiveService: Inside Constructor. Initializing Component");
InitializeComponent();
MyException.CreateLog("iMArchiveService: Component Initialized. Timer is set as: " + TimeMachine.Interval.ToString() + " milliseconds");
}
protected void TimeMachine_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable before condition is: " + isArchiving.ToString());
if (!isArchiving)
isArchiving = new iM.OrderArchiving.ArchiveOrderXML().ArchiveOrderService();
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable after condition is: " + isArchiving.ToString());
}
catch (Exception ex)
{
MyException.CreateLog("iMArchiveService: Inside Tick Catch :(");
}
}
protected override void OnStart(string[] args)
{
TimeMachine.Enabled = true;
MyException.CreateLog("iMArchiveService Started: " + DateTime.Now.ToString());
}
protected override void OnStop()
{
TimeMachine.Enabled = false;
MyException.CreateLog("iMArchiveService Stopped: " + DateTime.Now.ToString());
}
}
the code above is for service file.cs
here is my project installer file
namespace iM.OrderArchivingService
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
}
}
here is the InitializeComponenet Function -
private void InitializeComponent()
{
this.myServiceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.myServiceInstaller = new System.ServiceProcess.ServiceInstaller();
//
// myServiceProcessInstaller
//
this.myServiceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.myServiceProcessInstaller.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceInstaller});
this.myServiceProcessInstaller.Password = null;
this.myServiceProcessInstaller.Username = null;
//
// myServiceInstaller
//
this.myServiceInstaller.ServiceName = "iMArchiveService";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceProcessInstaller});
}
here is the program.cs file
namespace iM.OrderArchivingService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new iMArchiveService() };
ServiceBase.Run(ServicesToRun);
}
}
}
as u see i have written the code to log when in initializes or starts.. but no log is being made.
edit:
Code for Timer(TimeMachine)
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.TimeMachine = new System.Timers.Timer(3600000);
//
// TimeMachine
//
this.TimeMachine.Interval = 3600000;
this.TimeMachine.Elapsed += new System.Timers.ElapsedEventHandler(TimeMachine_Elapsed);
//
// iMArchiveService
//
this.ServiceName = "iMArchiveService";
}
thnx