添加C#引用对性能的影响 [英] The effect of adding C# Refrences on performance

查看:85
本文介绍了添加C#引用对性能的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个简短的问题.

我正在用C#编写WPF应用程序.我想添加一个通知图标.为此,我需要引用System.Windows.Forms.NotifyIcon.

我的问题是添加"using System.Windows.Forms.NotifyIcon"语句的效果如何.

Hi, I have a quick question.

I am writing a WPF application in C#. I want to add a Notify Icon. To do this I need to reference System.Windows.Forms.NotifyIcon.

My question is what will the effect be of adding the "using System.Windows.Forms.NotifyIcon" statement.

Will this dramatically effect the performance of the program at run time?

推荐答案

仅在使用程序集时才打开和加载程序集,因此在您添加引用到项目之前不会起作用使用其中的类型(编译器将删除未使用的引用).

在运行时,性能取决于引用的使用方式和方式以及实现方式.通常,程序集的初始加载会有所延迟,但是稍后在冷启动应用程序(再次运行)时调用会更快.

为了减少初始加载时间,您可以考虑对组件进行NGEN设置,这将减少加载时间.
Assemblies are opened and loaded only when used, so adding references to your project have no effect until you use the types within it (the compiler will remove unused references).

At runtime performance is determined by what and how your references are being used and how they are implemented. Usually you will get a delay in the initial loading of the assemblies but later calls on cold start of your application (running again) will be faster.

To reduce the initial load time you can look into NGEN ''ing your assemblies which will reduce the load time.


好,应用程序确实需要执行特定任务.而且只有将通用功能模块化为单独的dll,然后在应用中引用并使用它们才有意义.显然,这些应用程序越多,应用程序的运行速度就会稍慢,因为它必须加载所有这些应用程序,如果dll不属于GAC的话,应用程序的整体大小也会增加.但是,好处是CLR通过称为JIT(准时生产)和Pre-JIT编译的方式优化了程序集的加载,这会延迟加载已编译的dll,直到其实际使用为止,即,当您从该dll调用方法时,您不必担心引用库,而不必担心GAC中的库.希望这对您有所帮助:)
well, an application does need what it needs to peform a certain task. And it only makes sense to modularise common functions into separate dlls that you then reference in your app and use them. The more of these you have, obviously, the app will be slightly slower because it has to load all these plus the overall app size also increases if the dlls are not part of the GAC. But the beauty is that the CLR optimises the loading of assemblies by something known as JIT(Just In-Time) and Pre-JIT compilation which delays loading a compiled dll until its actually used i.e. when you call a method from that dll so there is not much you can do worrying about referencing libraries, atleast the ones that are in the GAC. Hope this helps you a bit :)


这篇关于添加C#引用对性能的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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