我正在做一个办公室添加, 我需要显示一个显示进度的通知对话框, 我使用 < a href=" http://www.codeproject.com/ articles/ 36468/WPF- 通知Icon" rel=“ nofollow” > Philipp Sumi s wpf- notifificon 。
我需要显示 < a href=>" "http://www.codeproject.com/ artss/ 3646/68/WPF-通知Icon" rel="nofollow" >nofoltiticon 从一条单独的线索中显示 < a href=", 因为我有很多代码已经在主线上执行, 这就导致 wpf- notificiticon 屏蔽和等待, 因为窗口信息队列中的信息没有被处理 。
我知道,我宁愿在一条单独的线上执行这个消耗时间的代码,从主线上显示通知并相应更新,但不幸的是,这不是一个替代办法,因为整个解决方案都是单行读取的。
示例:
private FancyPopup fancyPopup;
private void button1_Click(object sender, EventArgs e)
{
notifyIcon = new TaskbarIcon();
notifyIcon.Icon = Resources.Led;
fancyPopup = new FancyPopup();
Thread showThread = new Thread(delegate()
{
notifyIcon.ShowCustomBalloon(fancyPopup, System.Windows.Controls.Primitives.PopupAnimation.Fade, null);
});
showThread.Start();
}
private void button2_Click(object sender, EventArgs e)
{
fancyPopup.TextB.Text = "Doing something...";
//Keep the main thread busy.
Thread.Sleep(5000);
fancyPopup.TextB.Text = "Done doing something...";
}
Update I have been able to progress a little further with this updated code:
我在新线索上创建任务barIcon 对象, 并使用 application.Run 处理该线索上的应用程序消息环...
private FancyPopup fancyPopup;
private void button1_Click(object sender, EventArgs e)
{
Thread showThread = new Thread(delegate()
{
notifyIcon = new TaskbarIcon();
notifyIcon.Icon = Resources.Led;
fancyPopup = new FancyPopup();
notifyIcon.ShowCustomBalloon(fancyPopup, System.Windows.Controls.Primitives.PopupAnimation.Fade, null);
System.Windows.Forms.Application.Run();
});
showThread.SetApartmentState(ApartmentState.STA);
showThread.Start();
}
private void button2_Click(object sender, EventArgs e)
{
fancyPopup.Dispatcher.Invoke(new Action(delegate
{
fancyPopup.TextB.Text = "Doing something...";
}));
//Keep the main thread busy.
Thread.Sleep(5000);
fancyPopup.Dispatcher.Invoke(new Action(delegate
{
fancyPopup.TextB.Text = "Done doing something...";
}));
}