0

我正在构建将保留在托盘中的应用程序,它会不时进行服务调用,如果服务返回结果,它将在右下角显示为漂亮的窗口。
我发现漂亮的组件作为 codeproject - http://www.codeproject.com/Articles/277584/Notification-Window 如果在表单应用程序中使用此通知效果很好,但是当我尝试从 ApplicationContext 显示它时它会停止我的应用程序- 通知正在显示,但是当我尝试点击它时,我没有收到响应错误。

class TrayContext : ApplicationContext
{
    private System.Timers.Timer appointmentTimer;
    private PopupNotifier notification;

    public TrayContext()
    {
        notification = new PopupNotifier
            {
                AnimationDuration = 500, 
                ContentFont = new System.Drawing.Font("Tahoma", 8F), 
                Image = null, 
                OptionsMenu = null, 
                Scroll = false, 
                ShowHandCursor = false, 
                Size = new System.Drawing.Size(400, 100), 
                TitleFont = new System.Drawing.Font("Segoe UI", 11.25F)
            };

        //timer
        appointmentTimer = new System.Timers.Timer();
        appointmentTimer.Interval = 600000;
        appointmentTimer.Elapsed += AppointmentTimerTimerElapsed;
        appointmentTimer.Start();
    }
    private void AppointmentTimerTimerElapsed(object sender, ElapsedEventArgs e)
    {
        appointmentTimer.Stop();
        notification.TitleText = "Test";
        notification.ContentText = "This should work";
        notification.Popup();
        appointmentTimer.Start();
    }
}

这是我得到的行为(光标忙而不是指针): 在此处输入图像描述

我试图使用委托来做到这一点,但是因为我使用的是 ApplicationContext 我没有 BeginInvoke 方法,但即使像下面这样添加它也无济于事:

private void BeginInvoke(Delegate callback, object[] args)
{
    syncContext.Post(state => callback.DynamicInvoke((object[])state), args);
}

我可以从 Form 中显示此通知,但我应该如何从 ApplicationContext 中显示它?

4

1 回答 1

0

I've figured this out.

I was using:

private System.Timers.Timer appointmentTimer;

it should be:

private System.Windows.Forms.Timer appointmentTimer;

But there is probably better solution for this. I'm not marking my answer as correct because I'll wait bit longer for maybe better answer.

于 2013-06-20T07:43:25.943 回答