.NET设计模式IDE执行代码frm3.5 vs.net 2010 [英] .NET design mode IDE executing code frm3.5 vs.net 2010

查看:62
本文介绍了.NET设计模式IDE执行代码frm3.5 vs.net 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让这个奇怪的事情开始:



我有一个叫做网络服务的应用程序,它运行正常。在.net中打开应用程序,它运行连接到Web服务的代码。我怎么知道这一点,我的异常是通过电子邮件处理的,我收到了大量的电子邮件和我的错误消息。不,f5没有被锁定。此外,当我尝试通过在解决方案中单击它来打开表单时,bingo; off再次尝试尝试Web服务。当我更改代码以注释掉EmailException()方法并构建它时,宾果游戏。另一封邮件。记住:这是设计时间,而不是运行时间。任何想法都是受欢迎的,因为在解决之前我将无法继续工作。是的,我已经尝试过计算机上的exsorcism:)

Let the wierdness begin:

I have an app that calls a webservice, it works fine. Opening the application in .net it runs the code that connects to the webservice. How do I know this, well my exceptions are handled through email, I am getting tons of emails with my error messages. No, f5 is not being keyed. Also, when I try to open a form by clicking on it in the solution, bingo; off goes another attempt at trying the webservice. And when I change the code to comment out the EmailException() method and build it, bingo. Another email. REMEMBER: this is in design time, not run time. Any ideas are welcome, since I won't be able to continue work on it until this is resolved. Yes, I already tried exsorcism on the computer :)

推荐答案

它很简单,在某个地方你可能有一个自定义控件或表单,你继承,并在那里表单你正在使用一些事件,如OnFormLoad或OnHandleCreated,并对你的网络服务做一些事情。



.NET中的设计时间必须由你的代码处理,你在调用Web服务之前,需要检查表单或控件是否处于设计模式。设计模式不是特殊的,它关闭所有后台代码和事件,表单和控件在设计模式下运行,就像在运行时一样。由您(开发人员)决定您处于设计模式并关闭您不想运行的代码部分。



虽然没有看到你的代码,但我无法告诉你检测它的最佳方法。表单和控件具有非常可靠的DesignMode属性,但您需要执行多次检查。
Its pretty simple, somewhere you probably have a custom control or form that you are inheriting from, and in that form you are using some of the events like the OnFormLoad or OnHandleCreated and doing something with your web service.

Design time in .NET must be handled by your code, you need to check if the form or control is in design mode before calling your web service. Design mode isn't something special that shuts down all the background code and events, forms and controls run in design mode just like they do at runtime. Its up to you, the developer, to figure out that you are in design mode and shut down the parts of the code that you don't want to run.

Without seeing your code though, I can't tell you the best way to detect it. Forms and controls have a DesignMode property that is pretty reliable, but you need to do more than one check.


此代码是否在表单后面(无论是窗体还是WPF),以及你在展示设计师窗口吗?在这种情况下会出现这种类型的行为,因为VS设计器在设计器窗口中显示表单时实际执行表单的代码。我知道,这听起来很愚蠢,但是当我连接到DI通常会满足的界面时,我已经多次看到这种行为。
Is this code behind a form (be it a windows form or WPF), and are you showing the designer window? This type of behaviour is exhibited in this case because the VS designer actually executes the code for the form when it displays it in the designer window. I know, it sounds daft, but I have seen this behaviour many times when I've hooked up to an interface that would normally be satisfied by DI.


这篇关于.NET设计模式IDE执行代码frm3.5 vs.net 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆