Windows 10气球通知正常,Windows 11无显示问题求助
Windows 11下NotifyIcon气泡不显示的问题排查与解决
- 系统通知权限限制:Windows 11对通知管控更严格,先检查系统设置:打开「设置」→「系统」→「通知」,确保你的应用在「来自应用和其他发送者的通知」列表中处于开启状态,同时确认「通知横幅」未被关闭。
- 对象生命周期过短:你在方法里创建
NotifyIcon后,立刻用Thread.Sleep(10000)接着就Dispose(),但Windows 11的通知系统可能需要更长时间完成绑定,提前释放会直接销毁通知。建议把NotifyIcon设为类级成员变量延长生命周期,或者改用异步延迟释放,不要在主线程中Sleep阻塞。 - 图标规格不兼容:Windows 11对通知图标要求更高,确保
Logo_grey_white_fill是标准ICO格式,且包含256x256像素的高分辨率版本,低分辨率图标可能无法正常渲染。 - 非UI线程调用问题:
NotifyIcon属于WinForms控件,必须在UI线程执行才能正常工作。如果showBalloon是在非UI线程调用的,Win11下会无法显示气泡,需要用Control.Invoke(WinForms)或Dispatcher.Invoke(WPF)切换到UI线程执行逻辑。
修改后的示例代码
// 将NotifyIcon声明为类成员,延长生命周期 private static NotifyIcon _notifyIcon; public static void ShowBalloon(string title, string body) { // 确保在UI线程执行通知逻辑 if (System.Windows.Forms.Application.OpenForms.Count > 0) { var mainForm = System.Windows.Forms.Application.OpenForms[0]; mainForm.Invoke((Action)(() => { _notifyIcon = new System.Windows.Forms.NotifyIcon(); _notifyIcon.Visible = true; _notifyIcon.Icon = Properties.Resources.Logo_grey_white_fill; _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; if (!string.IsNullOrEmpty(title)) { _notifyIcon.BalloonTipTitle = title; } if (!string.IsNullOrEmpty(body)) { _notifyIcon.BalloonTipText = body; } // 绑定气泡关闭事件,在通知关闭后再释放资源 _notifyIcon.BalloonTipClosed += (s, e) => { _notifyIcon.Dispose(); _notifyIcon = null; }; _notifyIcon.ShowBalloonTip(30000); })); } }
注:如果是WPF应用,需用
System.Windows.Application.Current.Dispatcher.Invoke切换到UI线程,同时确保项目引用了System.Windows.Forms和System.Drawing程序集。
内容的提问来源于stack exchange,提问作者Max Headroom
相关产品推荐
相关产品推荐

