Saturday, November 24, 2018

c# - Visual Studio - Debug vs Release



I built a windows service, targeted for .NET 2.0 in VS 2008. I run it as a console app to debug it.



Console app is working great. I put it on my local computer as a service, compiled in debug mode, still working great. I'm ready to release now, and suddenly, when I set it to release mode, the service compiles and installs, but nothing happens. (No code in service is running at all).



I realize that the release vs debug mode are property configuration settings, but it seems that in release mode, even when I check define DEBUG constant, uncheck Optimize code, and set Debug info to 'full', it is still doing nothing.



Set it back to debug and it's working like a charm again.




(As a sidenote, I tried resetting the target framework to 3.5 to make sure that wasn't the issue, too)



So my questions (in order of importance) are these:




  1. Will using my "debug" version in any way ever cause any problems?


  2. What settings are different between debug and release besides the three I've been trying to change already?


  3. This seems like a weird error to me and has stirred up my curiosity. Any idea what would cause this?





EDIT:
Should mention, I already am using a custom installer. Basically I compile the program (in either debug or release) and then install it with the respective installer.


Answer



1) It might, if not directly, so indirectly by making the application slower and making it use more memory.



2) When it runs in debug mode, there are certain things that works differently, for example:




  • The code is compiled with some extra NOP instructions, so that there is at least one instruction at the beginning of each code line, so that it will be possible to place a break point at any line.



  • The instructions can be rearranged in release mode, but not in debug mode, so that the code can be single stepped and the result will correspond to the exact order of the source code.


  • The garbage collector works differently, by letting references survive throughout their entire scope instead of only for the time that they are used, so that variables can be viewed in debug mode without going away before the scope ends.


  • Exceptions contain more information and takes a lot longer to process when thrown.




All those differences are relatively small, but they are actual differences and they may matter in some cases.



If you see a great difference in performance between debug mode and release mode, it's usually because there is something wrong with the code, like for example if it's throwing and catching a huge amount of exceptions. If there is a race condition in the code, it may only happen in release mode because there is some extra overhead in debug mode that makes the code run slightly slower.



3) As to what the problem with your service is, I don't know, but it doesn't seem to be related to how the code is executed in debug mode or release mode. The code would start in any case, and if it was a problem with the code, it would crash and you would be able to see it in the event log.



No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...