Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 我的WPF应用程序在奇怪的时刻关闭_.net_Wpf_Vb.net_Visual Studio - Fatal编程技术网

.net 我的WPF应用程序在奇怪的时刻关闭

.net 我的WPF应用程序在奇怪的时刻关闭,.net,wpf,vb.net,visual-studio,.net,Wpf,Vb.net,Visual Studio,我的wpf应用程序中发生了一件非常奇怪的事情 每次我关闭某个东西(对话框、窗口等)时,整个应用程序都会关闭,而不仅仅是关闭的窗口/对话框 这不仅发生在我直接调用Close方法时,也发生在元素自己关闭时,例如:当我在对话框上单击“OK”时,它从ShowDialog()方法返回 而且,这不会立即发生,但只有在发生关闭事件的方法发生时才会发生。下面是一个更好的例子: Public Sub addNewCanvas(ByVal sender As Object, ByVal e As Execu

我的wpf应用程序中发生了一件非常奇怪的事情

每次我关闭某个东西(对话框、窗口等)时,整个应用程序都会关闭,而不仅仅是关闭的窗口/对话框

这不仅发生在我直接调用Close方法时,也发生在元素自己关闭时,例如:当我在对话框上单击“OK”时,它从ShowDialog()方法返回

而且,这不会立即发生,但只有在发生关闭事件的方法发生时才会发生。下面是一个更好的例子:

    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
我真的不明白为什么会这样。。。没有引发任何异常,输出日志或visualStudio没有什么可说的,所有变量都已正确地定值

如果你们有什么想法,请告诉我!这快把我逼疯了! 提前谢谢


Master_T

注意未处理的异常: 在调试中启动应用程序并打开异常窗口(调试->异常或我的计算机上的Ctrl+Alt+E),然后检查公共语言运行时异常抛出列。 然后执行正常操作,查看是否引发任何未处理的异常


如果这使您更接近问题,请告诉我。

可能发生了一个未处理的异常,您无法捕获。尝试将事件处理程序附加到应用程序类
DispatcherUnhandledException
事件。

好的,在提出问题后不久就解决它(当然……你花了一个小时思考,然后在寻求帮助后发现问题:D)

问题是我正在开发的应用程序是由一位以前的员工启动的,我刚才注意到他使用了一种奇怪的方式启动应用程序。他基本上是将应用程序实例传递给GUI,然后GUI使用自身的实例初始化应用程序。。。我真的不明白他为什么做了这么奇怪的事,不管怎样,我是这样解决问题的:

app.ShutdownMode = ShutdownMode.OnExplicitShutdown

无论如何,谢谢你的帮助!(顺便说一句,这没有引起任何异常…

很棒的提示,只是帮我省了几个小时!