Windows 服务通知用户 WPF Outlook 样式控件不可见

发布于 2024-07-13 07:39:52 字数 1496 浏览 8 评论 0原文

更新:我们在工作中仍在使用 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 桌面警报博客

感谢您的帮助!

Update: We are still using XP at work and I got my solution working, but now knowing that Vista and beyond have the isolated session I am going to implement a WCF IPC...

I have a windows service that needs to notify the user of an event of some type occurring. I decided that something similar to email notification messages would make sense. It also makes sense to do such a simple UI using WPF. This would allow me to learn some basics.

I run a thread:

Thread thread = new Thread(new ThreadStart(RunUserNotificationOnIndependantThread));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

Then I set up the object and call the method that calls 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);
    }

The debugger reaches BeginAnimation(...) and no window appears. Is this even possible or what am I doing wrong in attempting this???

The UserNotification code is based on a blog by Nicke Andersson: WPF Desktop Alert blog

Thanks for any help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

已下线请稍等 2024-07-20 07:39:52

在 XP 上,与桌面交互的服务有两个严重的问题需要克服 - 当没有用户登录时该怎么办以及当多个用户登录时该怎么办(快速用户切换和终端服务是两种最常见的登录方式)超过一个用户)。

在 Vista 上,出于安全原因,服务在其自己的独立桌面上运行,因此您显示的任何 UI 都将运行在任何用户都无法访问的特殊桌面上。

您应该编写一个在用户桌面上运行的小型 Gui 程序,并使用某种类型的 IPC(远程、Soap、Rest、命名管道、文件,无论您喜欢什么)与服务进行通信。

On XP a service that interact with the desktop has two serious problems to overcome - what to do when no users are logged in and what to do when several user are logged in (fast user switching and terminal services are the two most common ways to log in more then one user).

On Vista, for security reasons, services run on their own isolated desktop so any UI you show will go on that special desktop that no user can ever access.

You should write a small Gui program that runs on the user's desktop and communicate with the service using some type of IPC (Remoting, Soap, Rest, named pipes, files, whatever you like).

寄风 2024-07-20 07:39:52

一般来说,我根本不推荐 Windows 服务直接与用户桌面交互。 举一个简单的例子,由于服务可能在任何用户登录之前启动,因此会出现问题。 我的建议是创建一个小型应用程序,该应用程序随用户会话启动,并通过 IPC(进程间通信)(例如 WCF)与 Windows 服务进行通信。

但如果你确实想尝试让它运行,我的提示是打开该服务的“允许与桌面交互”,我似乎记得这个开关在 Vista 下根本不起作用,但其他人应该确认这一点。

华泰
亚历克斯

Generally speaking I would not recommend a Windows Service to interact with the user's desktop directly at all. As a simple example, problems arise because the service may start before any user is logged on. My suggestion would be to create a small app that start-up with the user session and communicated to the Windows Service via IPC (Interprocess Communication) such as WCF.

But if you do want to try to get it running, my hint would be switch on "Allow interaction with desktop" for the service and I seem to remember that this switch doesn't work at all under Vista, but someone else should confirm that.

HTH
alex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文