How to drive VS.NET crazy

VS.NET has a tight integration with SQL server. From the server explorer you can browse your databases, view or update any data in them and even do a lot of design stuff. You can see some examples in this dnj article. The only thing I haven’t found in there is the administration of sql user accounts. But there is a price to be paid, I’m not exactly sure what is going on but some things are leaking. Having altered some tables and having had some app-crashes while debugging my machine slows down. Restarting VS solves that. Closing down VS form such a state is a long wait.


I found out there is a faster way to slow down VS. Take this scenario. For an app I had created a couple of components. The components open the db connection when created, close it when disposing and house a couple of dataAdapters. The pages of my app will use the component, to make them easy to use I added a couple of component properties to the app’s base web form. Something like this


public class BaseForm : System.Web.UI.Page
{
    private IprojektData pd;
    public IprojektData Projekt
    {
        get
            {
                if (pd == null)
                    pd = new ProjektData.DataComponent();
            return pd;
        }
    }
 


The properties have a “lazy” creator, the actual component is not created until it is actually needed. And when the component is not used on the page it will not be created at all.


The pitfall is making the properties public. When you design a page based on this base class the component properties will show up in the property window. The property value is computed and the component will be created. Leading to a lot of (failing) database activity in the web-form designer. Not needed and this really can cripple your machine very fast. The solution is pretty straightforward, just set the browsable attribute on the properties to prevent the properties showing in the property window. Like this


[Browsable(false)]


public IprojektData Projekt
{
    get
        {
            if (pd == null)
                pd = new ProjektData.DataComponent();
        return pd;
    }
}
 


Now the property won’t show up in the window, the componenet is only created at run-time and VS will keep running.


Blog on,Peter

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Peter

    Great job !

    But after all, VS.NET is just the old COM based VS 6 in a new coat. If you look at it that way it’s not bad. Have you ever used Delphi ? Great language but its IDE will make you love VS.

    I’m lookng forward what the new VS will bring. Afaik 2005 is still based on the same vs and Orcas (vs for longhorn) fill be a completely new IDE.

  • Justin Lovell

    You think that is crazy? I have some code that can crash VS.NET without running a single instance of the solution that I am building :-).

    Here is the URL for the code that crashes the IDE perfectly (does not even prompt me to send an error report as well :-):

    http://blogs.aspadvice.com/jlovell/archive/2004/04/05/920.aspx

    However, there is a built-in thing that you can crash VS.NET 2003 (will not work for VS.NET 2002) — it is also got to do with XML Schemas + some innocent user patterns with the Schema designer == VS.NET hanging at 51 MB of memory and 71% of the CPU.