tags:

views:

231

answers:

2

I want send some data on server, before window close. I use event closing, but it doesn t wokr. Where is a problem?

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

    }
A: 

Did you check if there's a problem on _obj.CloseConnection()? Try to debug your code and check if the event handler is called.

Maurizio Reginelli
A: 

Try overriding OnClosing in the window code behind, See you can have a chance to not really closing the window if you got something else to do by e.Cancel = false.

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

       if(!isClosed)
          e.Cancel = false;

    }
Jobi Joy