2010-03-09 260 views
2

我想在窗口关闭之前在服务器上发送一些数据。我使用活动结束,但它并没有wokr。问题在哪里?关闭WPF窗口

private void Window_Closing(object sender, RoutedEventArgs e) 
    { 
      _obj.CloseConnection(); 

    } 

回答

0

您是否检查_obj.CloseConnection()是否存在问题?尝试调试您的代码并检查是否调用了事件处理程序。

6

尝试在窗口代码后面覆盖OnClosing。您有机会通过设置e.Cancel = true来阻止窗口关闭。

protected override void OnClosing(System.ComponentModel.CancelEventArgs e) 
    { 
     bool isClosed = _obj.CloseConnection(); 

     if(!isClosed) 
      e.Cancel = true; 

    }