在高优先级下运行应用程序

你是否注意到,当你在高优先级下运行应用程序是,应用程序运行得特别快(这也视你运行什么样的应用程序而定)。拿WinRar做例子测试,你会发现解压缩要比正常优先级下快一些,但是也有一些应用程序性能要比正常优先级下性能差,所以在确定这样设置之前,先做测试,看是否能够比正常优先级下得到更高的性能。

 

如果你现在可以自由的更改应用程序的代码,你可以用下面代码做测试:

       C#: 

System.Diagnostics.Process myProcess = System.Diagnostics.Process.GetCurrentProcess();
myProcess.PriorityClass 
= System.Diagnostics.ProcessPriorityClass.High;

 

      VB:

Dim myProcess As System.Diagnostics.Process = _
        System.Diagnostics.Process.GetCurrentProcess()
myProcess.PriorityClass 
= System.Diagnostics.ProcessPriorityClass.High

你要做的就是在加载窗体前或任何你想改变进程优先级的地方使用此代码就可以了。 

 

还有一种非常简单的解决方案:运行应用程序时使用/<priority>选项,选项列表如下:

 

  1. realtime(实时)
  2. high(高)
  3. normal(正常)
  4. low(低)
  5. abovenormal (Windows 2000 only)(高于正常)
  6. 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 /start /low calc

 

 同时发布于us178.com  CSDN.NET

 原文:CodeProject 

 

 

posted on 2010-10-19 17:48  Ferry  阅读(1210)  评论(0编辑  收藏  举报

导航