使用System.Management是一个失礼?

编程入门 行业动态 更新时间:2024-10-28 16:18:15
本文介绍了使用System.Management是一个失礼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一般来说,使用System.Management是一种失礼吗?经过一些网上搜索后,似乎有相当多的阻力,因为 的速度和便携性。 我需要知道有多少CPU插槽。我正在使用 System.Management来执行此操作。这需要大约两秒钟的时间。 (对于速度来说,这是完全废弃的。)但是更好的方法是什么?b 确定数量Windows版本的CPU套接字> = 5,带有 a .NET> = 2.0应用程序?

Is using System.Management in general a faux pas? It seems, after some web searching, that there is a fair amount of resistance to it because of speed and portability. I need to know how many CPU sockets there are. I''m using System.Management to do this. It takes about two seconds to do this. (Which, yes, is full-on crap for speed.) But what is the better way to determine the number of CPU sockets in Windows version >= 5 with a .NET >= 2.0 application?

推荐答案

not_a_commie, 使用System.Management命名空间,为了易用性和可维护性(通过统一的对象模型),您将权衡性能 和 查询语法)。我确信有更快的代码可以找到它, 但它很可能是使用互操作,如果没有正确完成,可以 影响轻松 - 使用和可维护性。 所以最后,这是一个权衡,像所有的权衡,你必须 做出决定哪一个更符合您应用的需求。 - - Nicholas Paldino [.NET / C#MVP] - mv*@spam.guard.caspershouse " not_a_commie" < no ******** @ gmailwrote in message news:11 ********************* @ d30g2000prg.googlegro ups ... not_a_commie, With the System.Management namespace, you are trading off performance for ease-of-use, and maintainability (through a unified object model and query syntax). I am sure that there is much faster code to find this out, but it is most likely done with interop, which if not done correctly, can impact ease-of-use and maintainability. So in the end, it is a trade off, and like all trade offs, you have to make the decision which one is better for your application''s needs. -- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse "not_a_commie" <no********@gmailwrote in message news:11*********************@d30g2000prg.googlegro ups... 一般情况下使用System.Management是一种失礼吗?经过一些网上搜索后,似乎有相当多的阻力,因为 的速度和便携性。 我需要知道有多少CPU插槽。我正在使用 System.Management来执行此操作。这需要大约两秒钟的时间。 (对于速度来说,这是完全废弃的。)但是更好的方法是什么?b 确定数量Windows版本的CPU套接字> = 5,带有 a .NET> = 2.0应用程序? Is using System.Management in general a faux pas? It seems, after some web searching, that there is a fair amount of resistance to it because of speed and portability. I need to know how many CPU sockets there are. I''m using System.Management to do this. It takes about two seconds to do this. (Which, yes, is full-on crap for speed.) But what is the better way to determine the number of CPU sockets in Windows version >= 5 with a .NET >= 2.0 application?

" ; not_a_commie" < no ******** @ gmailwrote in message news:11 ********************* @ d30g2000prg.googlegro ups ... "not_a_commie" <no********@gmailwrote in message news:11*********************@d30g2000prg.googlegro ups... 一般情况下使用System.Management是一种失礼吗?经过一些网上搜索后,似乎有相当多的阻力,因为 的速度和便携性。 我需要知道有多少CPU插槽。我正在使用 System.Management来执行此操作。这需要大约两秒钟的时间。 (对于速度来说,这是完全废弃的。)但是更好的方法是什么?b 确定数量Windows版本的CPU套接字> = 5 a .NET> = 2.0应用程序? Is using System.Management in general a faux pas? It seems, after some web searching, that there is a fair amount of resistance to it because of speed and portability. I need to know how many CPU sockets there are. I''m using System.Management to do this. It takes about two seconds to do this. (Which, yes, is full-on crap for speed.) But what is the better way to determine the number of CPU sockets in Windows version >= 5 with a .NET >= 2.0 application?

Environment.ProcessorCount,返回的数量为处理器,但这不是你想要的。$ / b $ b从WMI获取CPU单位数不应超过50 msecs。 你用什么操作系统和什么WMI课程。 Willy。

Environment.ProcessorCount, returns the number of processors, but this is not what you are looking for. Getting the CPU unit count from WMI should however not take more than 50 msecs. What OS and what WMI class are you using for this. Willy.

" Willy Denoyette [MVP]" < wi ************* @ telenet.bewrote in message news:呃************** @ TK2MSFTNGP06。 phx.gbl ... "Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message news:uh**************@TK2MSFTNGP06.phx.gbl... " not_a_commie" < no ******** @ gmailwrote in message news:11 ********************* @ d30g2000prg.googlegro ups ... "not_a_commie" <no********@gmailwrote in message news:11*********************@d30g2000prg.googlegro ups... >一般情况下使用System.Management是一种失礼吗?经过一些网页搜索之后,似乎有很大的阻力,因为它的速度和便携性。 我需要知道有多少CPU插座。我正在使用 System.Management来做到这一点。这需要大约两秒钟的时间。(其中,是的,是关于速度的完全废话。)但是,确定Windows版本中CPU插槽数量的更好方法是> = 5,一个.NET> = 2.0应用程序? >Is using System.Management in general a faux pas? It seems, after someweb searching, that there is a fair amount of resistance to it becauseof speed and portability.I need to know how many CPU sockets there are. I''m usingSystem.Management to do this. It takes about two seconds to do this.(Which, yes, is full-on crap for speed.) But what is the better way todetermine the number of CPU sockets in Windows version >= 5 witha .NET >= 2.0 application?

Environment.ProcessorCount,返回处理器数量,但这是 不是你想要的。 从WMI获取CPU单位数不应超过50 msecs。 你用什么操作系统和什么WMI课程。 Willy。

Environment.ProcessorCount, returns the number of processors, but this is not what you are looking for. Getting the CPU unit count from WMI should however not take more than 50 msecs. What OS and what WMI class are you using for this. Willy.

以下: int processors; SelectQuery query = new SelectQuery(从 Win32_Processor中选择Deviceid); 使用(ManagementObjectSearcher) searcher = new ManagementObjectSearcher(查询)) { ManagementObjectCollection processor = searcher.Get(); processors = processor.Count; } 需要30 ... 40msecs。在我的盒子上运行时。 请注意,第一次调用可能需要一些操作系统版本的时间, 因为系统必须启动WMI(当时尚未启动) 。 启动,无论如何,如果您的 系统的CPU或/和内存资源不是很低,这应该是*多*小于2秒。 威利。

Following: int processors; SelectQuery query = new SelectQuery("select Deviceid from Win32_Processor"); using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { ManagementObjectCollection processor= searcher.Get(); processors = processor.Count; } takes 30...40msecs. when run on my box. Note that the very first call can take some more time on some OS versions, as the system has to start WMI (when not already). started, anyway, this should be *much* less than 2 seconds, provided your system is not running low on CPU or/and memory resources. Willy.

更多推荐

使用System.Management是一个失礼?

本文发布于:2023-11-08 22:24:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   System   Management

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!