1
Answer

windows service in vs2008

Ask a question
radha krishna

radha krishna

16y
2.1k
1

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.

 


Answers (1)