Silverlight ChildWindow 在回调时无法正确关闭

发布于 2024-11-15 00:31:13 字数 662 浏览 3 评论 0原文

我有一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘦怹 2024-11-22 00:31:13

关闭方法被调用两次,这不是我的情况。

我想可能是这样。考虑调用 DoSomething 两次,有多少委托已分配给 SaveCompleted 以及有多少已被删除?答:现已添加 2 个,没有删除任何一个。因此,当它第二次完成时,Close 将快速连续调用两次。

尝试此代码,该代码在委托被触发一次后将其删除。

public void DoSomething()
{
  var wait = new WaitingScreen();

  EventHandler<AsyncCompletedEventArgs> saveCompleted = null;

  saveCompleted  = (s, arg) =>
  {
    wait.Close();
    svc.SaveCompleted -= saveCompleted;
  };

  svc.SaveCompleted += saveCompleted;
  wait.Show();
  svc.SaveAsync();
}

话虽如此,我同意@zapico 使用工具包 BusyIndi​​cator 来完成此任务。

Close method being called two times, that's not my case.

I think it probably is. Consider having called DoSomething twice how many delgates have been assigned to the SaveCompleted and how many have been removed? Answer: 2 have now been added and none removed. Hence when it completes for the second time Close will be called twice in quick succession.

Try this code which removes the delegate after it has been fired once.

public void DoSomething()
{
  var wait = new WaitingScreen();

  EventHandler<AsyncCompletedEventArgs> saveCompleted = null;

  saveCompleted  = (s, arg) =>
  {
    wait.Close();
    svc.SaveCompleted -= saveCompleted;
  };

  svc.SaveCompleted += saveCompleted;
  wait.Show();
  svc.SaveAsync();
}

Having said all that I agree with @zapico use the toolkit BusyIndicator for this task.

栩栩如生 2024-11-22 00:31:13

要在等待异步调用时显示一个窗口,我将使用 silverlight 工具包 中的“BusyIndi​​cator”。

无论如何,如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文