Silverlight ChildWindow 在回调时无法正确关闭
我有一个简单的 ChildWindow 仅包含两个元素,文本块和进度条来模拟等待屏幕。该 ChildWindow 在调用异步 WCF 方法之前启动,并在回调时关闭。
问题是 ChildWindow 第二次关闭时整个表面保持禁用状态。我搜索过类似的情况,一个博客文章谈到 Close 方法被调用两次,这不是我的情况。
这是一些示例代码(svc 是 WCF 服务):
// global private class variable
private WaitingScreen wait = new WaitingScreen();
public void DoSomething()
{
svc.SaveCompleted += (s, arg) =>
{
wait.Close();
};
wait.Show();
svc.SaveAsync();
}
任何指针将不胜感激,我想我在这里缺少一些基本的东西。
I have a simple ChildWindow containing only two elements, textblock and a progress bar to simulate a waiting screen. That ChildWindow is started before calling async WCF method and closed on the callback.
The problem is the second time the ChildWindow is close the entire surface stay disable. I've search for similar situation, one blog post talked about the Close method being called two times, that's not my case.
Here is some sample code (svc is a WCF Services):
// global private class variable
private WaitingScreen wait = new WaitingScreen();
public void DoSomething()
{
svc.SaveCompleted += (s, arg) =>
{
wait.Close();
};
wait.Show();
svc.SaveAsync();
}
Any pointer would be appreciated, I think I'm missing something basic here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想可能是这样。考虑调用
DoSomething
两次,有多少委托已分配给SaveCompleted
以及有多少已被删除?答:现已添加 2 个,没有删除任何一个。因此,当它第二次完成时,Close
将快速连续调用两次。尝试此代码,该代码在委托被触发一次后将其删除。
话虽如此,我同意@zapico 使用工具包 BusyIndicator 来完成此任务。
I think it probably is. Consider having called
DoSomething
twice how many delgates have been assigned to theSaveCompleted
and how many have been removed? Answer: 2 have now been added and none removed. Hence when it completes for the second timeClose
will be called twice in quick succession.Try this code which removes the delegate after it has been fired once.
Having said all that I agree with @zapico use the toolkit BusyIndicator for this task.
要在等待异步调用时显示一个窗口,我将使用 silverlight 工具包 中的“BusyIndicator”。
无论如何,如果 WaitingScreen 是一个 ChildWindow,它应该返回一个值(Accept 或 Cancel)来关闭。也许这就是问题所在。
To show a window while you wait for an asynchronous call I would use "BusyIndicator" from silverlight toolkit.
Anyway, if WaitingScreen is a ChildWindow, it should return a value (Accept or Cancel) to close. Maybe that's the problem.