更新:我们仍在工作中使用 XP,我的解决方案正在运行,但现在知道 Vista 及更高版本具有隔离会话,我将实施 WCF IPC...
我有一个 Windows 服务需要通知用户发生某种类型的事件。我认为类似于电子邮件通知消息的东西是有意义的。使用 WPF 做这样一个简单的 UI 也是有意义的。这将使我能够学习一些基础知识。
我运行一个线程:
Thread thread = new Thread(new ThreadStart(RunUserNotificationOnIndependantThread));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
然后我设置对象并调用调用 DoubleAnimation.BeginAnimation 的方法
private void RunUserNotificationOnIndependantThread()
{
UserNotificationWithImage test = new UserNotificationWithImage();
test.Title = _title;
test.Url = _url;
test.Message = _message;
test.LoadUserNotification();
}
public void LoadUserNotification()
{
Rect workAreaRectangle = System.Windows.SystemParameters.WorkArea;
Left = workAreaRectangle.Right - Width - BorderThickness.Right;
Top = workAreaRectangle.Bottom - Height - BorderThickness.Bottom;
_fadeInAnimation.Completed += new EventHandler(_fadeInAnimation_Completed);
// Start the fade in animation
BeginAnimation(UserNotificationBase.OpacityProperty, _fadeInAnimation);
}
调试器到达 BeginAnimation(...) 并且没有出现任何窗口。这甚至可能还是我在尝试这个时做错了什么???
UserNotification 代码基于 Nicke Andersson 的博客:WPF Desktop Alert blog
谢谢你的帮助!!