views:

80

answers:

3

Hi guys!

I have a really weird thing happening in my wpf application.

Every time I close something (a dialog box, a window, etc...) the ENTIRE application closes, instead of only the window/dialog which is beeing closed.

This not only happens when I call the Close method directly, but also when the element closes on it's own, eg: when I click "OK" on a Dialog and it returns from the ShowDialog() method.

Also, this doesn't happen immediately, but only when the method in which the close event occourred. Here's an example to explain it better:

    Public Sub addNewCanvas(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim dlg As New addCanvasDgBox
    Dim result As Nullable(Of Boolean) = dlg.ShowDialog
    'The following if is executed, and so is the addCanvas() method
    If (result = True) Then
        addCanvas()
    End If
End Sub
'Here comes the problem: efter the routine is ended instead of returning
'to the normal execution, the entire App.Run() method returns, closing the application

I really don't understand why this happens... no exceptions are raised, the output log or visualStudio have nothing to say, all variables are correctly valorized.

If any of you has any ideas, please let me know! It's driving me insane! Thanks in advance.

Master_T

A: 

Watch for unhandled exceptions: Start the application in debug and open the exceptions window( debug->exceptions or Ctrl+Alt+E on my machine) and check the Common Language Runtime Exceptions, the Thrown column. Then do your normal operations and see if any unhandled exceptions are thrown.

Let me know if this got you closer to the problem.

Ando
A: 

Perhaps there is an unhandled exception occurring that your not catching. Try attaching an event handler to the app classes DispatcherUnhandledException event.

Simon P Stevens
+1  A: 

Ok, figured it out shortly after asking the question (of course... you pass an hour wondering and then you find the problem moments AFTER you asked for help :D )

The problem was that the app I'm working on was started by a previous employee and I noticed just now that he used a weird way to start the application. He basically passes the Application instance to the GUI which then initializes the Application with an instance of itself... really don't understand why he did something so weird, anyway I solve the problem this way:

app.ShutdownMode = ShutdownMode.OnExplicitShutdown

Thnx anyway for the help! (it wasn't rising any exceptions by the way...)

Master_T