【发布时间】:2012-03-17 13:27:00
【问题描述】:
我使用一个弹出窗口的控件。我有一个显示和隐藏它的方法,我需要实现一个功能来防止在不同线程中显示和隐藏我的弹出窗口。我可以在非 UI 线程中显示我的弹出窗口吗?
更新
我的问题的主要目标是:
方法 Show 从哪个线程开始并不重要,Method Hide 应该在同一个线程中。如何实现?
public void Show()
{
IsShown = true;
if (this.ChildWindowPopup == null)
{
this.ChildWindowPopup = new Popup();
try
{
this.ChildWindowPopup.Child = this;
}
catch (ArgumentException)
{
throw new InvalidOperationException("The control is already shown.");
}
}
if (this.ChildWindowPopup != null && Application.Current.RootVisual != null)
{
// Configure accordingly to the type
InitializeProgressType();
// Show popup
this.ChildWindowPopup.IsOpen = true;
}
}
public void Hide()
{
IsShown = false;
// Restore system tray
SystemTray.IsVisible = currentSystemTrayState;
this.progressBar.IsIndeterminate = false;
this.ChildWindowPopup.IsOpen = false;
}
【问题讨论】:
-
能不能简单的在显示的时候保存Thread.CurrentThread,隐藏的时候看看是否一样?仍然 - 我认为这个问题表明另一个问题。为什么要检查线程?如果目标是显示某些操作的进度条 - 您可以创建一些对象(令牌)以将进度条与操作相关联。除了调试另一个问题之外,我不明白您为什么要按照建议的方式管理线程。
标签: c# silverlight windows-phone-7 silverlight-4.0 silverlight-3.0