Debugging Design-Time Functionality


Because components implement functionality for both run time and design time, you need to test and debug them in both modes. To test run-time functionality, you simply set a breakpoint in your component's code and run a test application, relying on the VS05 debugger to break at the right moment.

Debugging design-time functionality is different because components are hosted within another application's design-time environment, and thus debugging is unavailable by default. To debug in the design time, you create a special environment that requires a design-time host to debug against. Because the hands-down hosting favorite is VS05 itself, this means that you use one instance of VS05 to debug another instance of VS05 with a running instance of the component loaded. This may sound confusing, but it's easy to set up:

1.

Open the VS05 solution that contains both the component and the hosting application.

2.

Set a second instance of VS05 as your debug application by going to Project | Properties | Debug and setting the following properties on your component project:

  • Set Start Action to Start External Program.

  • Set the external program to VS05IDEPath\devenv.exe.

  • Set Command Line Arguments to SolutionPath\SolutionName.sln.

3.

Choose Set As StartUp Project on the project that contains your component.

4.

Set a breakpoint in the component code.

5.

Use Debug | Start (F5) to begin debugging.

At this point, a second instance of VS05 starts up with your solution, allowing you to break and debug at will, as illustrated in Figure 11.4.

Figure 11.4. Design-Time Debugging


Using this debugging technique, it becomes obvious that the timer's Tick event is firing at design time, leading to constant control repainting. Somehow, AlarmClockControl needs to determine when it's executing at design time and, if it is, prevent such behavior.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net