using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
//using System.Windows.Forms;
using System.Timers;
namespace WindowsService1
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer proc_timer;
private System.ComponentModel.IContainer components;
public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
// this.timer1 = new System.Windows.Forms.Timer();
// this.timer1.Tick += new EventHandler(Timer_Ticker);
this.proc_timer = new System.Timers.Timer();
this.proc_timer.Elapsed += new ElapsedEventHandler(proc_Timer_Ticker);
this.ServiceName = "gds_status_process";
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnStart(string[] args)
{
this.proc_timer.Interval = 1000;
this.proc_timer.AutoReset = true;
this.proc_timer.Start();
FileStream fs = new FileStream(@"c:\temp\gds_status_process_log.txt" , FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine("gds_status_process: service started");
m_streamWriter.Flush();
m_streamWriter.Close();
}
protected override void OnStop()
{
FileStream fs = new FileStream(@"c:\temp\gds_status_process_log.txt" , FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine("gds_status_process: service stopped");
m_streamWriter.Flush();
m_streamWriter.Close();
this.proc_timer.Stop();
}
private void proc_Timer_Ticker (object sender, System.Timers.ElapsedEventArgs e)
{
FileStream fs = new FileStream(@"c:\temp\gds_status_process_log.txt" , FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine("tick - " + DateTime.Now.ToString());
m_streamWriter.Flush();
m_streamWriter.Close();
}
}
}