views:

133

answers:

4

How is that setting a breakpoint in my code allows the following code to complete which would fail otherwise.

Here is the problem.

I'm writing an add-on for SAP B1 and encountered following problem.

When I load a form I would like to enter some values into the form' matrix.

But without a breakpoint (set on a method in which loading a form takes place) the part of code that is executed afterward will fail. That part of code is referencing a matrix that is not yet displayed which results in an exception. This is all clear. But why setting a breakpoint "solves" the problem.

What is going on?

I suspect that my breakpoint introduces some delay between loading and displaying my form and part of code that references element of that form but I could be wrong.

+1  A: 

Having breakpoints means that every time a module is loaded at runtime Visual Studio scans the module for the positions of possible breakpoints. This must introduce a delay.

Vlad
might this scan happen if you have any breakpoints or not?
Sam Holder
@Sam: if you have breakpoints, the scan definitely happens; if you don't have breakpoints, there might be other reasons for scan as well. You can easily check that by measuring startup time for a heavy application with and without breakpoints.
Vlad
+2  A: 

Running under the debugger does slow your app and will often hide race conditions even without a breakpoint. When you introduce a breakpoint, it is even more likely to hide race conditions. These kind of problems can be difficult to solve. You might want to introduce some simple logging (e.g. log4net) to see what it is going on without impacting the app so much that you see different behavior. Just keep in mind that even logging can be enough to change things.

Tom Cabanski
+1  A: 

Is this a Windows Forms based application? (I'm afraid I know nothing about SAP B1) Try putting your code into the Load event of the form if it is not already there. Some controls aren't ready to use properly until their handle has been allocated which doesn't happen until the windows message loop has run a few times.

Mark Heath
+1  A: 

Breakpoints do introduce some delay. A breakpoint is the addition of extra instructions to your programs regular execution. Both hardware and software breakpoints ADD something to the execution of the program (although the amount would widely vary).

http://en.wikipedia.org/wiki/Breakpoint

CDSO1