Is it possible to send Toast notification from console application?

Evaldas B picture Evaldas B · Jun 27, 2016 · Viewed 16.6k times · Source

Is it possible to send Toast notifications from console application using ToastNotificationManager ?

I know that it is possible to send Toast notifications from Windows Universal app:

var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);

*doc - Toast stored in XML string

To use ToastNotificaionManager I need Windows.UI.Notifications library which I can't reference in console application project.

The library I mentionet before is actualy used by WinRT. Is it possible to use WinRT APIs in Windows console application ?

Answer

Evaldas B picture Evaldas B · Jun 27, 2016

At first you need to declare that your program will be using winRT libraries:

  1. Right-click on your yourProject, select Unload Project
  2. Right-click on your yourProject(unavailable) and click Edit yourProject.csproj
  3. Add a new property group:<targetplatformversion>8.0</targetplatformversion>
  4. Reload project
  5. Add reference Windows from Windows > Core
    enter image description here

Now you need to add this code:

using Windows.UI.Notifications;

and you will be able to send notifications using this code:

var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);

Reference: How to call WinRT APIs in Windows 8 from C# Desktop Applications - WinRT Diagram