Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to *completely* disable Edit and Continue?

I was wondering if there was a way to completely lock my code while debugging it within Visual Studio 2008. The code documents lock automatically when running as 64 bit applications, which I greatly prefer; however, I do most of my coding making add-ins for Excel, which is 32 bit. The result is that even though I target 'AnyCPU', the VS host knows that it is running within a 32 bit process and, therefore, the source code is not locked while the code is running hosted in Visual Studio.

I can turn off Edit and Continue by going to Tools > Options > Debugging > Edit and Continue, and then unchecking the 'Enabled Edit and Continue' check box. This does not completely lock the code, however. This does prevent any edits in the code from being executed in the current run, but it does not prevent mouse clicks or keystrokes from actually changing the code.

Again, when working with 64 bit applications this does not occur -- the code is completely locked. I greatly prefer the code to be completely locked for at least a couple of reasons:

  1. I can accidentally hit a key or the like while debugging, which I definitely do not want to do. It's rare, but it is an issue.

  2. Many of my automated tests drive the user interface via SendKeys. When stepping through such a test using the debugger, however, I can sometimes forget that some of the aspects involve SendKeys, which means that keystrokes wind up getting sent to the Visual Studio IDE instead of Excel.

In issue #2, above, the unit test fails, which is fine -- my bad -- but having all the keystrokes sent to the code module and destroying my code is completely unacceptable.

Does anyone have any ideas here? Can one completely lock the code when running hosted in Visual Studio while compiled against a 32 bit CPU?

Some related posts on this issue, but none of which directly address this:

  • How to: Enable and Disable Edit and Continue
  • “Changes to 64-bit applications are not allowed” when debugging in Visual Studio 2008
  • How do I enable file editing in Visual Studio’s debug mode?
  • How does “Edit and continue” work in Visual Studio?
  • Can we edit our code while running the application
  • Editing C# while debugging

Thanks in advance for any help or ideas...

Mike

like image 914
Mike Rosenblum Avatar asked Jan 12 '10 15:01

Mike Rosenblum


People also ask

How do I disable debugging in Visual Studio 2010?

Select Stop debugging from Debug menu to end a debugging session. You also can stop debugging from the processes window. In that window, right-click the executing process and select the Detach Process or Terminate Process command.


2 Answers

Here is a trick I use under Visual Studio 2005 (don't have a chance to test under Visual Studio 2008, but it should work):

  • Open the executable assembly's properties
  • Go to the Debug tab
  • Check the Enable unmanaged code debugging checkbox

The code documents should stay locked, even when a breakpoint is hit, and any attempt to change it should trigger a popup saying "Changes are not allowed when unmanaged debugging is enabled".

like image 135
Laurent Etiemble Avatar answered Oct 25 '22 15:10

Laurent Etiemble


Hey there - sorry I can't help you with completely locking your code - I have the opposite desire: to completely UNLOCK it during debug, but I can help you with your second issue.

I suggest that you consider checking the active window before sending any keys and if the active window is other than your target site, pause the execution of your test until focus is returned that that window.

I know it's not the solution you want, but it probably wouldn't hurt to prevent other similar issues.

Best of luck!

Adam

like image 24
Adam G. Carstensen Avatar answered Oct 25 '22 15:10

Adam G. Carstensen