在高优先级下运行应用程序
你是否注意到,当你在高优先级下运行应用程序是,应用程序运行得特别快(这也视你运行什么样的应用程序而定)。拿WinRar做例子测试,你会发现解压缩要比正常优先级下快一些,但是也有一些应用程序性能要比正常优先级下性能差,所以在确定这样设置之前,先做测试,看是否能够比正常优先级下得到更高的性能。
如果你现在可以自由的更改应用程序的代码,你可以用下面代码做测试:
C#:
System.Diagnostics.Process myProcess = System.Diagnostics.Process.GetCurrentProcess();
myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
VB:
Dim myProcess As System.Diagnostics.Process = _
System.Diagnostics.Process.GetCurrentProcess()
myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.High
System.Diagnostics.Process.GetCurrentProcess()
myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.High
你要做的就是在加载窗体前或任何你想改变进程优先级的地方使用此代码就可以了。
还有一种非常简单的解决方案:运行应用程序时使用/<priority>选项,选项列表如下:
- realtime(实时)
- high(高)
- normal(正常)
- low(低)
- abovenormal (Windows 2000 only)(高于正常)
- belownormal (Windows 2000 only) (低于正常)
要做到这一点,你所要做的就是使用start命令,语法如下:
start /{priority} {application}
例如:
start /high winword
start /low notepad
"C:\YourDirectory" start /realtime YourApplication.exe
or even from run command
cmd /c start /low calc
start /low notepad
"C:\YourDirectory" start /realtime YourApplication.exe
or even from run command
cmd /c start /low calc
原文:CodeProject
分类:
Windows应用程序
, .NET
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述