Debugging does not stop after closing a form in Visual Studio

Visual Studio Debug does not stop when I close the form I am writing in C #. How can I stop the debugging process when I close the form. I added the Application.Exit () method to the form closing event, but that didn't work.

Thanks.

+6
source share
4 answers

Try it from here.

If (System.Windows.Forms.Application.MessageLoop) { // Use this since we are a WinForms app System.Windows.Forms.Application.Exit() } Else { // Use this since we are a console app System.Environment.Exit(1) } 

EDIT:

If there are infinite threads then do

 Thread myThread = new Thread(...); myThread.IsBackground = true; //set your running thread to background myThread.Start(...); 

And can you see how to do this? from here

+5
source

It’s good that it will be too late, but I thought that I would send it to everyone who is faced with this problem (for example, I just did it), sorry in advance if this is quite simple, I am pretty new in C #, so this threw me a little.

I had the same problem as OP where in my FormClosing event neither Application.Exit () nor Environment.Exit (0) would complete the debugger.

What I found is to look at the link count above my FormClosing event, it shows "0 links". I just copied and pasted the final event from another forum, so there was no event handler to handle the event that I created / copied.

One easy way to resolve this (in addition to copy and paste code) is to create an event handler:

  • First go to the tab "Form1.cs [Design]"
  • Go to the "Properties" field
  • Click "Events"
  • Find "FormClosing" and double click on it

If you had the same problem, you should now see that there is at least 1 link to the event. Now when you close the form, it should also stop the debugger.

+1
source

Another possibility is that your process is running in an exception that is not being handled correctly. I used to show exceptions in self-build dialogs, but forgot to show the created window in one case. Thus, the program fell into an exception, created a window, but simply did not indicate any signs of this ... therefore the process continued to work even when I closed the application.

0
source

I landed on this question because VS did not stop when the debugged application was closed.

One of the ways to see what ide can cause is to freeze by pausing the mouse and clicking on the Debug Location toolbar to see all the threads that are still running. For me, I noticed that there is still a RabbitMq context that has not been deleted. So that was the key I needed.

After I made the code change, VS stops debugging it after the application exits.

I know this is not a solution you can expect, but figuring out why applications do not exit properly or still keep background processes is a very difficult question. Active threads drop out, this is the best place to look for imho.

0
source

Source: https://habr.com/ru/post/913113/


All Articles