开发者

Silverlight ChildWindow do not close properly on callback

开发者 https://www.devze.com 2023-03-12 00:37 出处:网络
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 callb

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):

开发者_如何学Python
// 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号