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:
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 DebuggingUsing 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. |