Alex Zhukovskiy
Alex Zhukovskiy

Reputation: 10025

Self-install of WInService

I've googled this one

but when i'm trying to apply it i get an error. So install/uninstall works fine, but service itself just doesn't start and after timeout it says that service doesn't respond. I don't know why. When i'm attaching to process it even doesn't enter into Main() method, static constructors and so on. I've used this addon for attach.

    public static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += OnException;

        if (Environment.UserInteractive)
        {
            AskUserForInstall();
        }
        else
        {
            ServiceBase.Run(new NotificatorService());
        }
    }

Service is also very simple:

using System.ServiceProcess;
using System.Windows;

namespace AZNotificator
{
    public partial class NotificatorService : ServiceBase
    {
        static NotificatorService()
        {
            int x = 5;
        }
        public NotificatorService()
        {
            InitializeComponent();
        }

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

        protected override void OnStop()
        {
        }
    }
}

Upvotes: 1

Views: 252

Answers (1)

Davor Zlotrg
Davor Zlotrg

Reputation: 6050

You can not call MessageBox.Show("Hello"); from the windows service since the service does not have the GUI.

If you want to do some interaction from the windows service have a look at this article

http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx

So remove MessageBox.Show("Hello"); from your OnStart method and your service should start just fine.

Upvotes: 2

Related Questions