Anirudha
Anirudha

Reputation: 32807

Why is my custom Windows service not doing its work?

I have created a service which would show "Hello World" message when it starts.. The OnStart method of the service consists the following code:

protected override void OnStart(string[] args)
{
    System.Windows.Forms.MessageBox.Show("Hello World");
}

The service is installed perfectly, but when I start the service I get the following error.

The RucService on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the performance Logs and Alert service.

Error Message

So it does not show the message Hello World. Why is this happening?

Upvotes: 0

Views: 678

Answers (2)

Chris Trombley
Chris Trombley

Reputation: 2322

Keep services & UI separate. Bad practice to try & use Windows Froms from within a service. If you need to integrate the two, you can try using sockets or some other IPC mechanism.

Upvotes: 1

Joel C
Joel C

Reputation: 5567

Don't try to use UI elements (Windows Forms) from a service. A service shouldn't have a UI component. If there needs to be a user interface for configuration, etc., have the service pull its settings from a database and create a separate application for managing the configuration.

Upvotes: 4

Related Questions