简体   繁体   English

VS2010设计器窗口正在执行我的表单

[英]VS2010 designer window is executing my form

Am I crazy or is this normal operation. 我疯了还是这个正常的操作。 Visual Studio 2010 SP1. Visual Studio 2010 SP1。

I have a .NET 3.5 (C#) base form with a few inherited classes. 我有一个.NET 3.5(C#)基本表单,其中包含一些继承的类。 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. 示例:我需要我的表单来启动在FormLoad事件中创建的命名管道服务器。 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. 我还可以通过进程浏览器看到,当我不调试时,devenv.exe正在启动我的管道实例。

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块中,如下所示:

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

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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