首页 > 解决方案 > 如何从 Windows 服务启动 Winforms 应用程序

问题描述

您好,我正在尝试winforms从当前会话的 Windows 服务启动一个交互式进程 - 一个应用程序。我不知道该怎么做。我正在使用TopShelf并尝试WhenSessionChanged使用TopShelf. 我可以得到sessionId

 var exitCode = HostFactory.Run(x => {
                    x.Service<MyService>(s => {
                        s.ConstructUsing((h) => new MyService());
                        s.WhenStarted(t => t.Run());
                        s.WhenStopped(t => t.Stop());
                        s.WhenSessionChanged((anubis, args) => {
                              string winformsPath="D://WinFormsApp/Wf.exe"
                              int sessionId = args.SessionId;
                              Process process = new Process();
                              process.StartInfo = new ProcessStartInfo(winformsPath);
                              process.Start();
                         });
                    });
                    x.RunAsLocalSystem();
                    x.SetServiceName(Constants.ISO.NAME);
                    x.SetDisplayName(Constants.ISO.DISPLAY);
                    x.SetDescription(Constants.ISO.DESCRIPTION);
                });

我不知道该怎么办sessionId
PS
我没有发布定义,MyService因为它在我们的案例中并不重要。我只想在当前会话中启动winforms。

标签: winformsprocesswindows-servicesinteractivetopshelf

解决方案


推荐阅读