assembly.createinstance运行缓慢 [英] assembly.createinstance works slow

查看:225
本文介绍了assembly.createinstance运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我正在执行A.EXE,我想从其他应用程序打开一些表单并在A.EXE中显示。让我们有另一个名为B.EXE的Windows应用程序。我想在A.EXE中打开一个表单,该表单是在B.EXE中设计的。 assembly.createinstance方法让我实现了这个目标,但我发现它在某些情况下运行缓慢:如果它是第一次打开在B.EXE中设计的表单,并且B.EXE很大。我无法忍受我需要超过10秒才能打开儿童表格。我怎么能批准这个表现呢?



我正在维护一个系统。我想使用一个应用程序打开许多表单,但它们在另一个应用程序中定义。所以,A.exe是我的主要应用程序,我有很多像B这样的应用程序。我可以在我的主应用程序中打开外部表单,但有时候很慢。我希望有一种方法可以让它更快。

解决方案

你无法改进它。你的观察是正确的:你所做的事情比其他大多数反射方法都要慢。



你应该检查你的架构。反射是一个不同的有价值的特征,但在大多数情况下,通过名称找到任何东西是使用它的最糟糕的想法之一。特别是,如果拼错名称,编译器将无法帮助您。你根据一些硬编码的字符串值来做自己。你对目标的非常不完整的描述并不能说服你真的想要它。有更好的方法,但在我能理解你的终极目标之前,我无法给你任何想法。



-SA

Hello.

I'm executing A.EXE, I want to open some forms from another apps and show in A.EXE. Let there be another windows application named B.EXE. I want to open a form in A.EXE, and that form is designed in B.EXE. assembly.createinstance method make me achieve this goal, but I found it works slowly in some situation: if it is the first time opening a form designed in B.EXE, and B.EXE is large. I can't stand that I need more than 10 sec to open a child form. How could I approve the performance?

I am maintaining a system. I want to use one application to open many forms, but they are defined in another applications. So, A.exe is my main application, and I have many apps like B. I can open outer forms in my main app, but sometimes slow. I wish there is a way to make it faster.

解决方案

You cannot improve it. Your observation is correct: what you do is relatively slow, as most of other reflection methods.

You should review your architecture. Reflection is a vary valuable feature, but finding anything by name is one of the worst ideas of using it, in most cases. In particular, if you misspell the name, a compiler won't help you. You make yourself depending on some hard-coded string values. Your very incomplete description of your goals does not convince me that you really want it. There are much better approaches, but I cannot give you any idea before I can understand your ultimate goals.

—SA


这篇关于assembly.createinstance运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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