i have written a windows service should open notepad automatically every 5 seconds. But the notepad is not opening. The following is my code.
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Diagnostics;using
System.Linq;using
System.ServiceProcess;using
System.Text;using
System.Threading;namespace
WindowsService1{
public partial class MyNotePadService : ServiceBase{
public MyNotePadService(){
InitializeComponent();
}
protected override void OnStart(string[] args){
// TODO: Add code here to start your service.EnableTimer();
}
public void EnableTimer(){
timer1.Enabled =
true;timer1.Start();
}
protected override void OnStop(){
// TODO: Add code here to perform any tear-down necessary to stop your service.timer1.Enabled =
false;}
private void timer1_Tick(object sender, EventArgs e){
Process processNotePad = new Process();processNotePad.StartInfo.FileName =
"notepad.exe";processNotePad.Start();
Thread.Sleep(5000);}
}
}
after building the code, in the command prompt i am installing the service and in the Services window pane my service is getting displayed, when i right click and choose the option "Start" nothing is happening.
Dipal ChoksiPosted May 9, 2008, 5:24 AM
Have you checked the task list, for processes by all users? The notepad executable may be running in a different user context and may not be visible on your desktop