Click here to Skip to main content
15,888,527 members
Articles / Programming Languages / Visual Basic

Running Applications on A Higher Priority

Rate me:
Please Sign up or sign in to vote.
4.33/5 (8 votes)
7 Sep 2010CPOL1 min read 45.6K   15   1
Running Applications on a Higher Priority

Did you notice that when you run a certain application on a Higher Priority, things are processed really quickly (this also depends on what application you are running), but take for example WinRar which is the one I tried. Things get zipped and extracted faster than it is on normal priority. But there are some applications that have slower performance than normal, I guess you have to test and see whether you would benefit in this solution.

Now if you are free to change the code, you can just do it like this in C#:

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

or VB:

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

and all you have to do is to invoke this before you load for Form or anywhere you want to change the Process priority.

But what if you don't have that luxury to do it in the code? Or the codes are just batch files or VBScripts which do not have rich objects and classes available for use like .NET. Yes, you can still do it by going to the task manager and assigning a process that priority but you don't want to do it anytime. There's another solution which is really easy and all you have to do is run the process with the /<priority> switch. Where the priority can be anything in this list:

  • realtime
  • high
  • normal
  • low
  • abovenormal (Windows 2000 only)
  • belownormal (Windows 2000 only)

Now to do that, all you have to do is to use the start command and here is the syntax:

start /{priority} {application},

Example:

start /high winword
start /low notepad
"C:\YourDirectory" start /realtime YourApplication.exe
or even from run command
cmd /c start /low calc

So you can use your imagination now if you want to use this in your scripts.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
New Zealand New Zealand
http://nz.linkedin.com/in/macaalay
http://macaalay.com/

Comments and Discussions

 
GeneralMy vote of 2 Pin
DanWalker15-Oct-10 8:17
DanWalker15-Oct-10 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.