This is the windows service which will invoke a application at 5.30 pm
Here I am invoking a web page
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Timers;
using System.Configuration;
using System.Globalization;
namespace WinWin
{
public class WinService1 : System.ServiceProcess.ServiceBase
{
///
/// Required designer variable.
///
///
// private System.Timers.Timer aTimer;
private System.ComponentModel.Container components = null;
//private System.Timers.Timer aTimer = new System.Timers.Timer();
//private System.ComponentModel.Container components = null;
private System.Timers.Timer aTimer;
public WinService1()
{
//System.Timers.Timer aTimer;
// 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
//private System.Timers.Timer aTimer;
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 WinService1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// WinService1
//
this.ServiceName = "WinService1";
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// Set things in motion so your service can do its work.
///
///
private Timer timer;
protected override void OnStart(string[] args)
{
if (aTimer == null)
{
aTimer = new System.Timers.Timer();
aTimer.Elapsed +=
new ElapsedEventHandler(OnTimer);
//Let the timer trigger once a minute
aTimer.Interval = 59000;
aTimer.Enabled = true;
}
else
{
aTimer.Start();
}
/*
// TODO: Add code here to start your service.
DateTime currentSystemTime = DateTime.Now;
//System.Timers.Timer aTimer = new System.Timers.Timer();
// Hook up the Elapsed event for the timer.
//aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
//aTimer.Interval = 2000;
//aTimer.Enabled = true;
// TODO: Add code here to start your service.
int i = 1;
if(i == 1)
{
if(currentSystemTime.Hour == 18 & currentSystemTime.Minute == 0)
{
//Console.WriteLine ("In the Main");
//Console.WriteLine ("In the Main");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="iexplore";
proc.StartInfo.Arguments="url";
proc.Start();
//proc.WaitForExit();
}
else
{
}
}
*/
}
private void InitializeTimer()
{
if (timer == null)
{
timer = new Timer();
timer.AutoReset = true;
timer.Interval = 60000 * Convert.ToDouble(
ConfigurationSettings.AppSettings["IntervalMinutes"]);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
}
private void timer_Elapsed(object source,System.Timers.ElapsedEventArgs e)
{
RunCommands();
}
private void RunCommands()
{
// JobRunWebService.JobRunInterval objJob =
// new JobRunWebService.JobRunInterval();
// objJob.RunJob();
}
///
/// Stop this service.
///
protected override void OnStop()
{
if (aTimer != null) aTimer.Stop();
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
public static void OnTimer(Object source,ElapsedEventArgs e)
{
RunDataLoader();
}
private static void RunDataLoader()
{
//Do your job in this procedure...
//while()
DateTime currentSystemTime = DateTime.Now;
//currentSystemTime.s
if(currentSystemTime.Hour == 17 & currentSystemTime.Minute == 30)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="iexplore";
proc.StartInfo.Arguments="url";
proc.Start();
}
}
protected override void OnPause()
{
if (aTimer != null) aTimer.Stop();
}
protected override void OnContinue()
{
if (aTimer != null) aTimer.Start();
}
}
}
Here I am invoking a web page
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Timers;
using System.Configuration;
using System.Globalization;
namespace WinWin
{
public class WinService1 : System.ServiceProcess.ServiceBase
{
///
/// Required designer variable.
///
///
// private System.Timers.Timer aTimer;
private System.ComponentModel.Container components = null;
//private System.Timers.Timer aTimer = new System.Timers.Timer();
//private System.ComponentModel.Container components = null;
private System.Timers.Timer aTimer;
public WinService1()
{
//System.Timers.Timer aTimer;
// 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
//private System.Timers.Timer aTimer;
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 WinService1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// WinService1
//
this.ServiceName = "WinService1";
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// Set things in motion so your service can do its work.
///
///
private Timer timer;
protected override void OnStart(string[] args)
{
if (aTimer == null)
{
aTimer = new System.Timers.Timer();
aTimer.Elapsed +=
new ElapsedEventHandler(OnTimer);
//Let the timer trigger once a minute
aTimer.Interval = 59000;
aTimer.Enabled = true;
}
else
{
aTimer.Start();
}
/*
// TODO: Add code here to start your service.
DateTime currentSystemTime = DateTime.Now;
//System.Timers.Timer aTimer = new System.Timers.Timer();
// Hook up the Elapsed event for the timer.
//aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
//aTimer.Interval = 2000;
//aTimer.Enabled = true;
// TODO: Add code here to start your service.
int i = 1;
if(i == 1)
{
if(currentSystemTime.Hour == 18 & currentSystemTime.Minute == 0)
{
//Console.WriteLine ("In the Main");
//Console.WriteLine ("In the Main");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="iexplore";
proc.StartInfo.Arguments="url";
proc.Start();
//proc.WaitForExit();
}
else
{
}
}
*/
}
private void InitializeTimer()
{
if (timer == null)
{
timer = new Timer();
timer.AutoReset = true;
timer.Interval = 60000 * Convert.ToDouble(
ConfigurationSettings.AppSettings["IntervalMinutes"]);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
}
private void timer_Elapsed(object source,System.Timers.ElapsedEventArgs e)
{
RunCommands();
}
private void RunCommands()
{
// JobRunWebService.JobRunInterval objJob =
// new JobRunWebService.JobRunInterval();
// objJob.RunJob();
}
///
/// Stop this service.
///
protected override void OnStop()
{
if (aTimer != null) aTimer.Stop();
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
public static void OnTimer(Object source,ElapsedEventArgs e)
{
RunDataLoader();
}
private static void RunDataLoader()
{
//Do your job in this procedure...
//while()
DateTime currentSystemTime = DateTime.Now;
//currentSystemTime.s
if(currentSystemTime.Hour == 17 & currentSystemTime.Minute == 30)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="iexplore";
proc.StartInfo.Arguments="url";
proc.Start();
}
}
protected override void OnPause()
{
if (aTimer != null) aTimer.Stop();
}
protected override void OnContinue()
{
if (aTimer != null) aTimer.Start();
}
}
}
Comments