I use Visual Studio 2005 & C#. In my FormClosing event I release some resources, that my application uses. But when I debug it and decide to stop (Stop debugging), than FormClosing event doesn't fire and my resources aren't properly released.
How can I avoid this?
If you by "resources" mean things like open handles and allocated memory, you shouldn't worry. The OS will release this as the process terminates.
If you mean things like temporary files, registry keys, or other things that are committed to disk that you want to clean up after yourself, I'm afraid you won't be able to catch that when terminating the program, and will have to clean it up manually or on next start. To my knowledge, at least. :)