sql-server - #WPF ToastNotifications 返回 2 个异常
问题描述
我正在使用 ToastNotifcations 来处理通过 Service Broker 来自我的数据库的更新。
用途:
using TableDependency.SqlClient.Base.Enums;
using ToastNotifications;
using TableDependency.SqlClient;
using ToastNotifications.Lifetime;
using ToastNotifications.Messages;
using ToastNotifications.Position;
using System.Data.Entity.Core.EntityClient;
代码:
private void _dependency_OnChanged(object sender, TableDependency.SqlClient.Base.EventArgs.RecordChangedEventArgs<Aircraft> e)
{
Notifier notifier = new Notifier(cfg =>
{
cfg.PositionProvider = new WindowPositionProvider(
parentWindow: Application.Current.MainWindow,
corner: Corner.BottomRight,
offsetX: 10,
offsetY: 10);
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
notificationLifetime: TimeSpan.FromSeconds(3),
maximumNotificationCount: MaximumNotificationCount.FromCount(5));
cfg.Dispatcher = Application.Current.Dispatcher;
});
if (e.ChangeType != ChangeType.None)
{
switch (e.ChangeType)
{
case ChangeType.Update:
e.Entity.ToString();
Console.WriteLine(e.Entity.ACStatus.ToString());
notifier.ShowWarning("I AM WORKING");
break;
}
}
}
private void Notify_Closing(object sender, CancelEventArgs e)
{
_dependency.Stop();
}
通过 Console.WriteLine 我得到了很好的结果,但是,notifier.ShowWarning
将出现以下异常:
Exception thrown: 'System.InvalidOperationException' in WindowsBase.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
有任何想法吗?
解决方案
推荐阅读
- node.js - 将csv数据导入mongodb节点js
- javascript - 数据表处理空 ajax 响应?
- chrome-devtools-protocol - 为什么找不到 Network.enable?
- angular - Agular 11 错误 TS2322:类型 'Observable<>
- flutter - Flutter 桌面忽略鼠标事件
- ios - 如何向 iOS 框架添加功能?
- python - 如何从循环中捕获 Cata
- android - ConstraintLayout & FrameLayout wrap_content 然后 FrameLayout 显示一半内容
- c# - 索引错误超出范围。必须为非负数且小于集合菜单的大小
- java - 如何将使用继承的程序转换为仅使用组合的程序?