简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM