我目前正在研究一個包含WCF服務,Windows服務和WPF應用程序的項目。 Windows服務與WCF通信,並且在某些情況下,必須啓動WPF應用程序以供用戶接收消息。 (WCF在遠程服務器上,其餘的在客戶端上)。發射時我遇到了一些障礙。我有服務將消息寫入應用程序日誌,以便我可以在某種程度上「調試」。 Windows服務運行下面的代碼沒有問題。Windows服務啓動和Exe
C#代碼,Windows服務:
WriteLog.WriteString("PostOffice.MessagesWaiting: Inside, starting up.", EventLogEntryType.Warning);
// Call the WPF Application
var messagingProcess = new Process();
var messageProcessStartInfo = new ProcessStartInfo(@"""C:\GoldenEyeMessages.exe""");
messageProcessStartInfo.CreateNoWindow = false;
messageProcessStartInfo.UseShellExecute = false;
messageProcessStartInfo.FileName = @"""C:\GoldenEyeMessages.exe""";
messageProcessStartInfo.WindowStyle = ProcessWindowStyle.Normal;
messageProcessStartInfo.Verb = "runas";
messageProcessStartInfo.RedirectStandardOutput = true;
messagingProcess.StartInfo = messageProcessStartInfo;
messagingProcess.Start();
StreamReader daStreamReaderMan = messagingProcess.StandardOutput;
string newString = daStreamReaderMan.ReadLine();
WriteLog.WriteString("PostOffice.MessagesWaiting: The Eagle has landed.", EventLogEntryType.Warning);
的WPF應用程序不能在當前用戶的會話中執行。相反,我得到一個彈出窗口來查看消息。下面是它的照片:
一旦選擇了「查看消息」選項,它當然我切換到不同的會話,然後運行WPF應用程序。
我的問題是,我該如何着手讓WPF應用程序在當前用戶會話或「活動」會話內啓動?
嗨 - 「WCF服務」,「Windows服務」和「WPF應用程序」都是完全不同的東西。更重要的是,它們都是完全不同的*種類*的東西。是的,他們都可以互相溝通:有很多方法可以做到這一點。是的,你可以進行設置,以便「事件」(例如,來自Windows服務的消息)可以觸發「操作」(甚至可能在用戶的桌面上啓動.exe)。但是否:Windows服務和WPF服務都存在於與用戶桌面完全不同的環境中。我不認爲你可以做你想做的事。 – paulsm4 2012-07-18 19:26:34
@ paulsm4:*默認情況下*它們存在於不同的上下文中。人們確實可以授予Windows服務權限與桌面進行交互。這樣做並不明智。 – 2012-07-18 19:29:58
@AngieLeigh:現在你有10個重點:-) – 2012-07-18 19:33:10