I am new to vb. When I started to work on this new project in vb.net 2010, I put many breakpoints to try to understand the execution order of the project, only to find it in vain.
Step into command F11 should work correctly according to Step Into Property/Function (F11) doesn't work as expected. But I when I pressed F11, I found the code is jumping from one place to another based on breakpoints, not line by line or step by step.
To give an example, please see the code below
Me.tcData.Alignment = TabStrip.TabControl.TabAlignment.Bottom 'line 1-breakpoint
Me.tcData.Dock = System.Windows.Forms.DockStyle.Fill 'line 2
...
Me.tcData.TabsDirection = TabStrip.TabControl.FlowDirection.LeftToRight 'line 3
Public Property Alignment() As TabAlignment 'The property 1 called by line 1
Get
Return m_Alignment
End Get
Set(ByVal value As TabAlignment)
m_Alignment = value
AdjustHeight()
PositionButtons()
For Each t As TabPage In TabPages
t.Alignment = value
Next
End Set
End Property
Public Property TabsDirection() As FlowDirection 'The property 3 -breakpoint
Get
Return m_TabsD开发者_如何学JAVAirection
End Get
Set(ByVal value As FlowDirection)
m_TabsDirection = value
SelectItem(Nothing)
End Set
End Property
When I press F11 at line 1, it goes to the property 1. After it returns, when I press F11,it goes to property 3 directly, without accessing the code in line 2 and line 3.
I do not understand why the code is NOT executed step by step by using F11. If I put breakpoingts in line 2, then line 2 is executed.
So it seems to me that the showed execution order is based on breakpoints! So if I put breakpoints at different places, the showed execution order would be different! Thus, it is impossible for me to really understand the execution order.
Thanks!
When you tell it to Step Into
, it follows the exact code path. So in order to calculate TabStrip.TabControl.TabAlignment.Bottom
in line one, it first has to reference TabStrip
, then look up the TabControl
property, then look up the TabAlignment
property, then-- Here's where it jumps to the property 1 label, right? That's because it has to execute the Get
section for the TabAlignment
property in your code. Once it executes that, it knows what the reference is, and so it returns that back to the previous level of execution, at which point it can look up the Bottom
property. Now, it can assign the value to the Me.tcData.Alignment
property.
The same goes for line 3: In order to know where it is assigning TabStrip.TabControl.FlowDirection.LeftToRight
to, it has to evaluate the Me.tcData.TabsDirection
property, which involves executing your code in the Get
section of your TabsDirection
property.
So, in short, you are seeing the exact execution path that the code is following, including all the "sub-evaluations" that have to be performed to calculate both the "source" and "destination" properties. Depending on the debugger configuration, it might not show this for system code, but if you set the debugger to be as verbose as possible, it will jump to the Get
definition for every property you reference, including system code. There are 5 property lookups for System.Windows.Forms.DockStyle.Fill
, just to assign it to a local variable.
精彩评论