如何在c#appliciton中使用总cpu处理 [英] how to use total cpu processing in c# appliciton

查看:67
本文介绍了如何在c#appliciton中使用总cpu处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友

i我在c#编程中使用线程以及如何在c#应用程序中使用线程中的所有RAM处理器。

帮助我。

解决方案

这太不可思议了。我们已经有很多问题让人们看到他们的应用程序根据他们的意见使用过多的CPU并希望减少这个数量。我不知道为什么。现在你要像其他一些询问者一样,要求使用所有CPU ;可能它意味着100%。



我不知道为什么有人会需要它。无论如何,几乎总是,如果有人设法在一个应用程序中使用大约100%的CPU,通常意味着这个应用程序做了一些非常愚蠢的事情。但是,如果这不是UI应用程序,并且所有其他应用程序都处于非活动状态(例如,其他应用程序的所有线程都处于等待状态,这是正常的事情;它会在所有UI应用程序中发生,然后不进行任何后台处理和没有用键盘或鼠标发送任何输入事件)然后,是的,这个唯一的应用程序的CPU使用百分比可能非常高。



否,单个CPU的使用率应用程序不仅仅由其应用程序定义。他们说,用法取决于操作环境。还有其他应用程序。但是开发人员开发不做傻事的应用程序非常重要,浪费CPU时间。 如果有人开发应用程序的目的是拥有一定比例的CPU使用率,无论是低还是高,这种愚蠢的事情几乎是不可避免的。



操作系统尽最大努力平衡使用可用CPU或CPU核心和加载进程的调度,并且很好地使用可用资源,不浪费它而不阻止其他进程,并且不让其他进程阻止你的进程。事实上,这很容易实现。这足以避免一些愚蠢的事情。



现在,只需要一个实用的建议:你可以改变线程和进程的优先级。 不要这样做。应该这样做的情况非常罕见,在所有其他情况下,你只会让事情变得更糟。首先,在你很好地理解应用程序应该做什么之前不要这样做。



-SA


Microsoft已经提出了.Net framework 4.0的Task Parallel librabrary

查看以下链接。

使用.NET 4.0的任务并行库进行多核编程 [ ^ ]

通过C#实现任务并行的基础知识 [ ^ ]

Dear friends
i am using thread in c# programming and how to use all RAM Processor in c# application with thread .
help me .

解决方案

This is incredible. We already had a number of questions where people see that their applications use, by their opinion, too much of CPU and want to reduce this amount. I don't know why. And now you are asking, like some other inquirers, honw to use all CPU; probably it means 100%.

I have no idea why anyone would need it. Anyway, nearly always, if some manages to use about 100% CPU in one application, it typically means that this application does something extremely stupid. However, if this is not UI application and when all other applications are inactive (say, all threads of other applications are in wait state, which is a normal thing; it happens with all UI application when then don't do any background processing and nobody sends any input events with keyboard or mouse) then, yes, the percentage CPU usage of this only application can be very high.

No, CPU usage of your single application is not defined by its application only. They say, the usage depends on the operating environment. There are other applications. But it's very important that developers develop applications which don't do something stupid, wasting CPU time. And such stupid things are nearly unavoidable if someone develop applications with the goal of having certain percent of CPU usage, no matter low or high.

The OS does its best to balance scheduling using available CPUs or CPU cores and loaded processes, and it's important to used the available resources well, not wasting it and not blocking other processes, and not letting other processes to block yours. And, in fact, this is pretty easy to achieve. It's just enough to avoid some stupid things.

Now, just one practical advise: you can change the priorities of the threads and processes. Don't do it. The cases when it should be done are extremely rare, in all other cases you can only make things worse. First of all, don't do it before you get to good understanding of what applications should do.

—SA


Microsoft has come up with Task Parallel librabrary with .Net framework 4.0
Check out below links.
Multi core programming using Task Parallel Library with .NET 4.0[^]
The Basics of Task Parallelism via C#[^]


这篇关于如何在c#appliciton中使用总cpu处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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