C# 右下角的ApplicationContext和消息窗口
我正在构建一个应用程序,该应用程序将停留在托盘中,它会不时地进行服务调用,如果服务返回结果,它将在右下角显示一个漂亮的窗口。C# 右下角的ApplicationContext和消息窗口,c#,.net,.net-3.5,applicationcontext,C#,.net,.net 3.5,Applicationcontext,我正在构建一个应用程序,该应用程序将停留在托盘中,它会不时地进行服务调用,如果服务返回结果,它将在右下角显示一个漂亮的窗口。我发现一个漂亮的组件作为codeproject- 如果在窗体应用程序中使用此通知,则此通知效果良好,但当我尝试从ApplicationContext显示它时,它会停止我的应用程序-通知正在显示,但当我尝试单击它时,我得到的不是响应错误 class TrayContext : ApplicationContext { private System.Timers.Tim
我发现一个漂亮的组件作为codeproject- 如果在窗体应用程序中使用此通知,则此通知效果良好,但当我尝试从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);
}
我可以从表单中显示此通知,但如何从ApplicationContext中显示它?我已经解决了这个问题
我使用的是:
private System.Timers.Timer appointmentTimer;
应该是:
private System.Windows.Forms.Timer appointmentTimer;
但可能有更好的解决办法。我不会把我的答案标记为正确的,因为我会再等一段时间,等待可能更好的答案