Tray notifications in C# and PowerShell
I’m working on a Pluralsight course on continuous integration and to demonstrate the process in the introduction module I made a make believe CI system in PowerShell, When a build step failed I wanted notifications, and tray notifications can be quite handy (emails as well of course).
trayNotificationPowershell
2014-01-31 17-50-05
This is how you create a tray notification in PowerShell or/and in C#. Remember to add a reference to System.Windows.Forms.
2014-01-31 17-48-35
2014-01-31 17-55-27
I’m using the PowerShell for Visual Studio extension to write (syntax highlighting, intellisense, debugging etc.) and execute PowerShell scripts in Visual Studio.
You can of course do the same things in Windows PowerShell ISE
PowerShell:
function Show-Balloon-Warning{
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
$tray = New-Object System.Windows.Forms.NotifyIcon
$tray.Icon = “C:\Users\IrisDaniela\Downloads\p.ico”
$tray.BalloonTipIcon = “Error”
$tray.BalloonTipText = “Iris you broke the build!!”
$tray.BalloonTipTitle = “Build failed”
$tray.Visible = $True
$tray.ShowBalloonTip(10000)
}
C#
- I’ll have to come back and add syntax highlighting to this later- I’m on the tram
using System.Drawing;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var tray = new NotifyIcon
{
Icon = new Icon(@“C:\Users\IrisDaniela\Downloads\p.ico”),
BalloonTipIcon = ToolTipIcon.Error,
BalloonTipText = “Iris your broke the build!”,
BalloonTipTitle = “Build Failed”,
Visible = true
};
tray.ShowBalloonTip(10000);
}
}
}
Comments
This seems to be a popular topic. Since NotifyIcon implements IDisposable you have to call Dispose when you are done with the NotifyIcon. If not, you have a memory/resource leak.
i want to make notification for my leave application project like facebook in asp.net with C# can u help me
Last modified on 2014-01-31