I'm trying to use the below code to show a Balloon notification. I've verified that it's being executed by using breakpoints. It's also showing no errors.
What should I do to debug this since it's not throwing errors and not showing the balloon?
private void showBalloon(string title, string body)
{
NotifyIcon notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
if (title != null)
{
notifyIcon.BalloonTipTitle = title;
}
if (body != null)
{
notifyIcon.BalloonTipText = body;
}
notifyIcon.ShowBalloonTip(30000);
}
You have not actually specified an icon to display in the task bar. Running your code in LINQPad, by simply adding
notifyIcon.Icon = SystemIcons.Application
before the call toShowBalloonTip
I was able to get the tip to be displayed. Also note that you should callDispose
when you are done with yourNotifyIcon
instance.ShowBalloonnTip takes the number of milliseconds. 3 milliseconds might be too fast for you to even see. Try something more like 3000
You might need to pass a component model to the contructor. It's what I see in all the examples. Sorry been a long time since I've used it. See first answer here:
NotifyIcon not showing
See the below source code.
Matthew identified the issue, but I still struggled to put all the pieces together. So I thought a concise example that works in LINQPad as-is would be helpful (and presumably elsewhere). Just reference the
System.Windows.Forms
assembly, and paste this code in.Take a look at the example here http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
I see some distinct differences between it an your code, there are many pieces you're leaving out such as creating a
ComponentModelContainer
and passing that into theNotifyIcon
's constructor.