Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send Toast notification from console application?

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 ?

like image 731
Evaldas B Avatar asked Jun 27 '16 19:06

Evaldas B


Video Answer


1 Answers

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

like image 124
Evaldas B Avatar answered Oct 06 '22 00:10

Evaldas B