set process priority of a procsses when ran

December 30, 2011 at 15:57:42
Specs: Windows 7
I have some code, it works, no errors, But I don't know how to add to important features to it

Keep in mine that I'm using notepad as an example.

A loop, This loop will keep looping until the process has been set to high priority, and once it's beem set it'll continue with the rest of the program.

Problem:When I add my loop, It eats 1/2 my CPU, and freezes the program, so you can't use or press any buttons in it, please help me.

Private Sub ProcessHigh()
Dim pslist() As Process
If Process.GetProcessesByName("notepad").Length = 0 Then
ListBox1.Items.Add("Waiting For Notepad.exe")
End If
psList = Process.GetProcesses()
For Each p As Process In psList
If p.ProcessName = "notepad" Then
p.PriorityClass = ProcessPriorityClass.High
ListBox1.Items.Add("Notepad.exe Has Been Set to high Priority")
End If
Next p
End Try
End Sub

So all I need is for this to be looped, to only say waiting for notepad once, keep looping until it's notepad had been set to high priority

Can i add the sleep function into the code, so it'll loop every 2 seconds, will this reduce the CPU consumption?

Thank you 2010

See More: set process priority of a procsses when ran

Report •

December 30, 2011 at 17:42:16
You sure can add a sleep function:


I had a program that will scan your computer constantly for files, and it took up 25% of my CPU. Adding that line of code with a 50 millisecond delay brought that down to 0%.

Also, you can run the code that sets the high priority using a Background Worker, they are very helpful, you can do other things in the program while the Worker does what it is programmed to do. Take a look at this for info:

Mouse could not be found. Click OK to continue.
What to do now?

Report •
Related Solutions

Ask Question