|
I have discovered a very annoying event that occurs at design time that I do not understand. My Visual Studio 2008 was crashing whenever I loaded a particular form in the VS form designer. I finally tracked the problem down to the Forms.Timer.
Apparantly when you load the designer the ticker fires the Tick event one time. In this tick event I make reference to an object that is null at design time... If I compile and run the project I get no problems at all. It is at design time that the nullReference occurs and crashes VS2008.
Is there a reason why the Tick event is being fired at design time? |
| CommanderKeen Tuesday, June 16, 2009 7:13 PM |
I find that setting in the Forms activate event works. This event is not fired at desgin time it would seem. - Marked As Answer byKira QianMSFT, ModeratorTuesday, June 23, 2009 5:35 AM
-
|
| CommanderKeen Friday, June 19, 2009 2:14 AM |
Hi CommanderKeen, Thank you for your feedback. This is a known issue on Microsoft Connect. The only solution is to enable timer only at run time. Please set the Timer's Enabled property to false in designer, set this property to true in the code when your form is load. Hope this helps. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Thursday, June 18, 2009 7:19 AM |
Thank you. This is actually how I ended up solving the problem. One thing has come apparant to me during all of this... When you create a new form (say we call it Form1) if we have a Load event the event does not trigger when you load Form1 in the designer... However if you create another Form say Form2 and inherit Form1 then when you load Form2 in the designer the Load event is fired in Form1 also if Form1 is to have a timer the Tick event is fired only for forms that are high in the hierarchy. To test I actually made calls to my database at design time. It worked and I was very surprised. This seems like un acceptable behavior and I'm very curious about it this issue.
|
| CommanderKeen Thursday, June 18, 2009 4:04 PM |
I'd just like to say well done for working out it was the Tick event - I'd just encountered this problem myself and I was wondering what the ____ was wrong with the designer. |
| DarrenMyatt Thursday, June 18, 2009 4:39 PM |
Yes it was a serious, serious and frustrating pain =]
|
| CommanderKeen Thursday, June 18, 2009 5:11 PM |
Hi CommanderKeen, Once you write some code in the class constructor or handle form "Load" event, it won't be run in the current form, it will be run in the inherited form in design time. Althrough I don't find any documentation talking about that, my test result and experience indicate you are right. In this situation, I think you should enable timer in the actual form which you need timer. Do not fire it in the base form. Sorry for the inconvenience. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Friday, June 19, 2009 2:12 AM |
I find that setting in the Forms activate event works. This event is not fired at desgin time it would seem. - Marked As Answer byKira QianMSFT, ModeratorTuesday, June 23, 2009 5:35 AM
-
|
| CommanderKeen Friday, June 19, 2009 2:14 AM |