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 st开发者_高级运维art 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.
So it does not show the message Hello World. Why is this happening?
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.
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.
精彩评论