Windows 服务通知用户 WPF 外观样式控件不可见 [英] Windows Service notifying user with WPF outlook style control not becoming visible

查看:49
本文介绍了Windows 服务通知用户 WPF 外观样式控件不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我们仍在使用 XP 并且我的解决方案有效,但现在知道 Vista 及更高版本具有隔离会话,我将实施一个WCF工控机...

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...

我有一个 Windows 服务,需要通知用户发生了某种类型的事件.我认为类似于电子邮件通知消息的内容是有意义的.使用 WPF 做这样一个简单的 UI 也是有意义的.这将使我能够学习一些基础知识.

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.

我运行一个线程:

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

然后我设置对象并调用调用DoubleAnimation.BeginAnimation的方法

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);
    }

调试器到达 BeginAnimation(...) 并且没有窗口出现.这是可能的还是我在尝试这个时做错了什么???

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

UserNotification 代码基于 Nicke Andersson 的博客:WPF 桌面警报博客

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

感谢您的帮助!!

推荐答案

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

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).

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

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.

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

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).

这篇关于Windows 服务通知用户 WPF 外观样式控件不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆