Have you ever use Visual Studio Form or User Control designer?
Have you ever run into construction error where the designer can't display your form?
Well, if you use Visual Studio, you would most likely have encounter error displaying your form if you:
A. manually manipulate the designer file (i.e. myForm.designer.cs)
B. you add runtime code to the form/user control's constructor causing your designer not to load.
Today, as I was working on my project, I don't know what I did to the code, but when I open my main form on the designer, Visual Studio crashed, and I got the following error:
At first, I thought it is something to do with the ActiveX control that I was referencing. I unregistered it and re-register it. No help at all. After I start playing around with my code by recreating my project, I found out what I did wrong.
It turns out that I add a System.Threading.Timer object to one of my user control's constructor. For example:
public partial MyUserControl : UserControl
{
//....
System.Threading.Timer myTimer = new Timer(DoSomeWork, null, 0, 180000);
//....
}
Since the user control is in any project, VS didn't crash until I rebuild the project and I reopen my main form that contains this user control. The confusing part is that instead of seeing error like the following, VS crashed and ask me to restart.
Hopefully the designer in Visual Studio 2008 will improve error handling and not crashing Visual Studio.
No comments:
Post a Comment