Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am creating a window service. my requirement is to display window form from window NT service on particular interval. For testing purpose , i just want to display the form on service start:

 protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart -before form show");

            Messager_Form obj = new Messager_Form();
            obj.Show();
           // System.Diagnostics.Process.Start("calc.exe");
            eventLog1.WriteEntry("In OnStart -after form show");
           // timer1.Start();
        }

it not working. Neither form is showing nor calc process is running. i have found some links showing pop up , but most of them suggesting WCF. isn't it possible without wcf. can anybody show me the way to achieve this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
431 views
Welcome To Ask or Share your Answers For Others

1 Answer

Cant be done*. In later Operating Systems that won't work as Windows Services are disallowed from interacting with the Desktop - instead UI presented by Windows Services is shown in Session 0, a special logon session which is not normally visible to the end user.

What you should instead do is write a separate Windows Forms application which is always running, but not always visible (possibly have that application run at startup and have an icon in the notification area) and communicates with the Windows Service using some form of IPC

When the Windows Service wishes to display some UI to the user it sends a message to the application, which in turns shows the desired UI to the end user.

**or at least it definitely shouldn't be done*


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...