Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Set Lower priority for Process


Reply
 
Thread Tools Display Modes
  #1  
Old 08-07-2008, 11:40 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default Set Lower priority for Process


I seem to be having an issue setting a lower priority for a process with VB2005.

I have code similar to the following
Code:
Dim MyProc As New System.Diagnostics.Process With MyProc.StartInfo .FileName = "TheProgram.exe" .Arguments = "/s /u" .CreateNoWindow = True .RedirectStandardInput = True .RedirectStandardOutput = True .UseShellExecute = False End With MyProc.Start() MyProc.PriorityClass = ProcessPriorityClass.BelowNormal
But setting the priority class does not seem to have any effect.
TheProgram is still using all available resources.
I even tried setting it to ProcessPriorityClass.Idle with no change.
The problem is when this program is running so are about 40 other applications. this application (a compression utility) is not a time critical task but most of the other applications are.

I tried setting the priority class prior to the start which of course failed (I was sure the process had to be running to set its priority)

Is there something I am overlooking? Or is there someting I am not understanding about how the ProcessPriorityClass works (This is quite possible) Any advice on how to get this process to operate at a lower CPU intensive rate are appriciated.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #2  
Old 08-08-2008, 07:29 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

From what I understand, the priority class is just an request that the OS schedule the process in a certain fashion when it's dealing out time slices.

The OS tries to give each process equal time slices; it runs one process for a while, then switches to another, and so on rather than running one process until it yields then moving on (of course if you yield it moves on.) The priority helps the OS decide which process to schedule next.

Processes with RealTime priority are always at the front of the list; it will get assigned most (if not all) of the time slices because nothing is more important. If you look at the documentation for the High priority, you see something neat: "The threads of the process preempt the threads of normal or idle priority class processes." This means that if the OS is deciding what to move to, and there's no other High priority processes, this process will be selected. This can have the same effect as RealTime: if there's only one high priority process it will take up all of the time slices. This pattern goes on all the way down to Idle, which can only get a time slice when nothing else wants one.

If your process consumes tons of system resources, it's going to use them during its time slice. Some actions, like disk I/O, might have side effects even when your process doesn't have a time slice. The best you might be able to do if setting a low priority doesn't help is examine your loops and call Sleep(0) liberally to yield your time slice quickly. I'd imagine doing this with an intensive compression operation might be a bad idea: if you're using a lot of RAM and the next process needs to use RAM, the OS has to page your stuff out and page the new process's stuff in; it may be better to use a higher priority.

Someone else probably knows more than me though, and I invite them to make me look like a fool so I can learn something
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 08-08-2008, 07:31 AM
kmoyle73 kmoyle73 is offline
Regular
 
Join Date: May 2006
Location: North Carolina
Posts: 69
Default

No doubt, AtmaWeapon is correct. It's the same as threading. You request your thread to sleep for a certain time period, but the OS may process it a fraction sooner or later. I have had the same thing happen to me, and it is completely frustrating.

Last edited by kmoyle73; 08-08-2008 at 07:37 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->