有没有在C#中的限制API的处理器资源的一种方式? [英] Is there a way of restricting an API's processor resource in c#?

查看:101
本文介绍了有没有在C#中的限制API的处理器资源的一种方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在外部API调用上工作的应用程序来处理特定请求的用户可以进行。这当然是一个seprate线程冻结或减慢尝试和prevent的UI做的。然而,外部API产生它自己的线程的质量和做一些处理器密集的工作。只要调用向它提出,CPU使用率上升到100%。这就锁定了我的UI。有没有在C#中限制可用的CPU使用率第三方API的方法吗?

The app I am working on calls upon an external API to process certain requests the user may make. This is of course done in a seprate thread to try and prevent the UI from freezing or slowing down. However, the external API produces it's own mass of threads and does some processor intensive work. As soon as calls are made to it, the CPU usage goes up to 100%. This then locks up my UI. Is there any way in C# of restricting the available CPU usage to a third party API?

推荐答案

我可以在这种情况下想到的唯一的事情,就是改变线程优先级。你可以增加你的UI线程的优先级一点,或尽量降低其他线程的优先级。

The only thing I can think of in this scenario, is change the thread priorities. You could increase your UI thread's priority a little, or try to lower the other thread's priorities.

后者被认为更恰当,但在你的情况有点棘手,因为你必须查询所有正在运行的线程,找出哪些是工作线程,并降低其优先级。你可能需要检测新的线程,也改变它们的优先级。

The latter is considered more proper, but in your case a bit tricky, as you will have to query for all running threads, find out which are the worker threads, and lower their priority. You probably need to detect new threads and alter their priority too.

这篇关于有没有在C#中的限制API的处理器资源的一种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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