0

I am new to .NET and seeking help for the Windows Service Updates Notifications.

I have a use case that is somewhat similar to "https://stackoverflow.com/questions/41232170/c-sharp-show-notification-prompting-a-update".

The application is developed in C#.NET and is deployed and running as Windows Service. However, the application is not using any MSI installer to install it. I am using a batch script that configures the Windows Service application.

Now, I want to show the notifications about the updates about the Windows Service to the user, when the system gets restarted.

I came across about the usage of WCF or by using the Task Scheduler, but not sure which one would be the better solution.

Please advice.

Avinash
  • 1,363
  • 2
  • 15
  • 28
  • i usually create a wcf service and host it in Windows Services. now do you want to push update notice to a client machine or server on which the service is running. also nee to now the type of binding and pattern you r using. – Muhammad Waqas Aziz Oct 23 '20 at 07:30
  • And do you care to share your batch script for installing the service in windows services – Muhammad Waqas Aziz Oct 23 '20 at 07:32
  • Hi Aziz, Thanks for your reply. The requirement is that the Windows Service will look for updates from the remote server every day if updates are available the notification pop-up should get displayed to the user on the system restart. About batch script - it uses normal "sc" command to create the service and to start the service. – Avinash Oct 23 '20 at 07:39
  • 2
    Services don't interact with any user desktops - you'd need a separate program running in the user's session. – Damien_The_Unbeliever Oct 23 '20 at 07:42
  • 1
    This is really duplicate of many "show UI from service" like https://stackoverflow.com/questions/2652254/how-can-i-display-a-system-tray-icon-for-c-sharp-window-service but this post got longer answer so... – Alexei Levenkov Oct 23 '20 at 07:56
  • *"to the user"* - There's your issue. Services run without a user being logged into the system. The number of users logged into a system at any given time is zero or greater. The term *"the user"* thus does not make sense in the context of system services. – IInspectable Oct 23 '20 at 08:09

1 Answers1

2

Ok, there are (were, because MS disabled the first one that I'm going to explain) two ways to notify your user about updates from a service.

First, the bad, ugly (and non-working in recent versions) way: interactive services.

You can configure a service as interactive, if you add the SERVICE_INTERACTIVE_PROCESS flag the service will be able to create a GUI that will be attached to Display_0. This presents a ton of problems (trying to show a GUI when there's no user session, if you have two sessions open only the first one will show the GUI and so on) but it's a cheap dirty way to show data to the user. Avoid it.

Second, the right way: a standalone GUI program.

In this case you create a secondary program that will show the data to the user, you can start it with the user session or let the user decide if he wants to receive info by opening manually this application. This program needs to receive the updates from the service in some way, which is better is up to you but I would use UDP for this, in this way your service doesn't needs to care if any GUI app is connected or not, you broadcast an UDP message and everyone listening will receive it, you don't need to mantain a server that handles connections, you don't need to have an storage in order to maintain the event data and it will support any number of instances of the GUI (if more than one user has started a session in the machine all of them will get notified).

But as I said, that would be my preference, you can do it as fancy as you want, you can use Pipes, use a file that contains the event and use a FileSystemWatcher to get notified when changes happen in it, you can even host an ASP .net web app which implements a SignalR hub and then you can create your GUI in html. It's up to you decide which mechanism is the best for your scenario.

Gusman
  • 14,905
  • 2
  • 34
  • 50
  • 1
    Hi Gusman, Thanks for your answer!! I think the second option will be the preferred one, where we can keep the secondary program running in the system tray, and as soon as the updates are available the notifications will be displayed to the user. – Avinash Oct 23 '20 at 11:05
  • There is no such thing as a *"system tray"*. There used to be the *"notification area"* that has been superseded by the *"action center"*. – IInspectable Oct 23 '20 at 11:13
  • @IInspectable the "notification area" is also known as *systray* or *system tray*, it may be wrong but everybody understand what it is. – Gusman Oct 23 '20 at 11:25