Hi , I have a windows service with a timer that checks for if a program is running or not.
If the program is running , it does not do anything but if not running , it starts the program from my program files where it was installed on the computer.
This check is for every 5 seconds.
When i put a break point , It works but on live environment , it does not work.
What am i missing ?.
Here is my code
public partial class Service1 : ServiceBase
{
System.Timers.Timer timer = new System.Timers.Timer();
public Service1()
{
InitializeComponent();
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(OnTimeEvent);
timer.Interval = 5000;
timer.Enabled = true;
}
protected override void OnStart(string[] args)
{
timer.AutoReset = true;
timer.Interval = 5000;
timer.Enabled = true;
timer.Start();
}
protected override void OnStop()
{
timer.AutoReset = false;
timer.Enabled = false;
}
protected void OnTimeEvent(object soucre, ElapsedEventArgs e)
{
timer.Stop();
if (FindAndKillProcess("RegistryKey") == false)
{
string file = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\kenteleTicketpopup\\Ticketpopupsetup\\Ticketpopup.lnk";
System.Diagnostics.Process.Start(file);
}
timer.Enabled = true;
}
public bool FindAndKillProcess(string name)
{
//here we're going to get a list of all running processes on
//the computer
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.StartsWith(name))
{
//clsProcess.Kill();
return true;
}
}
return false;
}
}
}
Please help to get this up and running.
Am suspecting might be the access to the programfiles on my PC.