Search code examples
c#visual-studio-2010designer

VS2010 designer window is executing my form


Am I crazy or is this normal operation. Visual Studio 2010 SP1.

I have a .NET 3.5 (C#) base form with a few inherited classes. Whenever I open the inherited form in designer view it actually starts running my code... I'm not even executing or debugging.

Example: I need my form to start a named pipe server which is created in the FormLoad event. Whenever I open the form in designer view, it actually starts up the pipe server.

Maybe I just don't fully understand how designer view works?

Edit: I know it's actually running because I'm trying to debug my pipe code and every time I open the designer window, it starts throwing pipe exceptions at me. I can also see through process explorer that devenv.exe is starting up my pipe instances when I'm not debugging.


Solution

  • Yes, the designer is actually "running" your form.

    If you want to avoid this, just put your critical code inside an if block like so:

    if(!this.DesignMode) //this is the Form
    {
    ....
    }
    

    Cheers