How to show form in windows service.

I want to load a form in the OnStart () method in my Windows service; here is my code. This does not work. Can you provide any help?

protected override void OnStart(string[] args)
{
    Form1 fr = new Form1();
    fr.Show();
}
+3
source share
4 answers

You cannot use services in this way. Services cannot interact directly with the desktop because they are launched in another WindowsStation from a login session. You need to create another application that will communicate with your service.

How to make a communication, which you can read on MSDN , and in this example . Some ideas have also been described already fooobar.com/questions/68717 / ... .

+2

. , .

" ", . . . . , ? , ?

, , .

+1

. (, , Application.Run).

, , ( ), .

0

" ". .

This is not enough to get a window to display reliably. In practice, you will have to determine if there is a user who is currently logged in and get your desktop. This is not a trivial obligation and can be a source of security problems. If no one is currently registered, you're out of luck.

The best solution is to have a separate graphical application that talks about the service through some IPC mechanism.

0
source

Source: https://habr.com/ru/post/1796646/


All Articles