Search code examples
c#wpfvisual-studio-2012keyevent

Visual Studio debugger does not exit after application was killed


Whenever I run the code via Visual Studio after second run it does not exit, meaning it is still running but visually it is down, yet it is visible via Taskmanager. I believe it has to do with buffer being filled with keys and it cannot handle the flow (after running the code without the method showed below it works fine).

 _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
    }

Above is the code where the method is being called when key is pressed it does call the method Controlling every time key press occurs.

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)
    {

    }
}

After second run and spamming key or keys it does not exit. Yet it works well when I run it directly (.exe).

Here is the Output:

       '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\12.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\12.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\12.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.

How would it be possible to make the software exit?


Solution

  • You may want to try setting

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

    This will force the application to shut down as soon as the Main window
    of your application has been closed.

    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.