Visual Studio 调试器在应用程序被杀死后不退出

Visual Studio debugger does not exit after application was killed

每当我 运行 通过 Visual Studio 的代码在第二个 运行 之后它不会退出,这意味着它仍然是 运行ning 但在视觉上它已关闭,但它可以通过 Taskmanager 看到。我相信这与缓冲区被键填充有关并且它无法处理流程(在 运行 没有下面显示的方法的代码后它工作正常)。

 _Controls _Movement; //Creates an object of the class

 public void MainWindow1_KeyDown(object sender, KeyEventArgs e) //Eventhandler method, being called when key is pressed.
    {
       if (_Movement == null) 
          { //assign value to the object ONCE
          _Movement = new _Controls(CharacterBody, CharacterFeet); 
          }
     _Movement.Controlling(e); //calling method whether the key is pressed
    }

上面是按下按键时调用方法的代码,它会在每次按键发生时调用控制方法。

class _Controls : MainWindow
{
    private RotateTransform rotateAll;
    private Image _CharacterBody, _CharacterFeet;

    public _Controls(Image _CharacterBody, Image _CharacterFeet)
    {
        this._CharacterBody = _CharacterBody;
        this._CharacterFeet = _CharacterFeet;
    }

    public void Controlling(KeyEventArgs e)
    {

    }
}

在第二个 运行 和垃圾密钥或密钥之后它不会退出。然而,当我直接 运行 它 (.exe) 时它运行良好。

这是输出:

       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Users\Unranked\documents\visual studio 2013\Projects\Shooter2D\Shooter2D\bin\Release\Shooter2D.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       The thread 0x1108 has exited with code 259 (0x103).
       The thread 0x1550 has exited with code 0 (0x0).
       The thread 0x1730 has exited with code 259 (0x103).
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Users\Unranked\documents\visual studio 2013\Projects\Shooter2D\Shooter2D\bin\Release\Shooter2D.exe'. Symbols loaded.
       Step into: Stepping over non-user code 'Shooter2D.App..ctor'
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       Step into: Stepping over non-user code 'Shooter2D.App.Main'
       Step into: Stepping over non-user code 'Shooter2D.App.InitializeComponent'
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
       'Shooter2D.vshost.exe' (CLR v4.0.30319: Shooter2D.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

如何让软件退出?

您可能想尝试设置

App.Current.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose;

这将强制应用程序在 Main window
您的应用程序已关闭。

Side note: It looks like you're trying to build a game loop, WPF might not be the best solution for that. You may want to look into MonoGame or Unity.