I am currently working on a windows service application that already consuming SignalR service. My new requirement is to start a desktop application when windows service receives a notification from SignalR.
While I am google on how to start a desktop application using windows service, I found this code base and I am currently using it.
As it explains, when I called the bellow method
ProcessExtensions.StartProcessAsCurrentUser(string path);
in the windows service's OnStart
method I was able to start the desktop application.
I also have SignalR
client in this windows service (Bellow code).
public class NotificationHub
{
public static void ConsumeNotification()
{
try
{
var hubConnection = new HubConnection(url);
IHubProxy notificationHubHubProxy = hubConnection.CreateHubProxy("WSMassageHub");
hubConnection.Start().Wait();
notificationHubHubProxy.On<WSMessage>("SendMessage", (message) => {
// try to start from here
// but it gives error
ProcessExtensions.StartProcessAsCurrentUser(@"D:\Application\Application.exe");
});
}
catch (Exception ex)
{
logger.Error("Message: " + ex.Message + " | Stack Trace: " + ex.StackTrace);
}
}
}
Then I try to start the desktop application from windows service when windows service gets the message to SignalR client.
protected override async void OnStart(string[] args)
{
NotificationHub.ConsumeNotification();
}
Once SignalR client gets a message, the application failed and error log gets this error message.
StartProcessAsCurrentUser: CreateProcessAsUser failed. Error Code -2
According to System Error Codes, it says that The system cannot find the file specified.
Also, I suspect that this will explain the issue in here. But I don't understand that which component needs to implement to start the desktop application, once SignalR client receives the notification. So, can someone please give me help hand to overcome this issue.
Thanks in advance.