Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetPriorityClass (kernel32)
 
.
Summary

VB Signature:

  <Runtime.InteropServices.DllImport("kernel32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto, CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _

<Runtime.InteropServices.DllImport("kernel32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto, CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _

  Public Shared Function SetPriorityClass( _
    ByVal hProcess As IntPtr, _
    ByVal dwPriorityClass As IntPtr _
    ) As Boolean
  End Function

C# Signature:

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool SetPriorityClass(IntPtr handle, PriorityClass priorityClass);

   public enum PriorityClass : uint
   {
       ABOVE_NORMAL_PRIORITY_CLASS = 0x8000,
       BELOW_NORMAL_PRIORITY_CLASS = 0x4000,
       HIGH_PRIORITY_CLASS = 0x80,
       IDLE_PRIORITY_CLASS = 0x40,
       NORMAL_PRIORITY_CLASS = 0x20,
       PROCESS_MODE_BACKGROUND_BEGIN = 0x100000,// 'Windows Vista/2008 and higher
       PROCESS_MODE_BACKGROUND_END = 0x200000,//   'Windows Vista/2008 and higher
       REALTIME_PRIORITY_CLASS = 0x100
   }

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]

public static extern bool SetPriorityClass(IntPtr handle, uint priorityClass);

User-Defined Types:

  Public Enum PriorityClass

Public Enum PriorityClass

    ABOVE_NORMAL_PRIORITY_CLASS = &H8000
    BELOW_NORMAL_PRIORITY_CLASS = &H4000
    HIGH_PRIORITY_CLASS = &H80
    IDLE_PRIORITY_CLASS = &H40
    NORMAL_PRIORITY_CLASS = &H20
    PROCESS_MODE_BACKGROUND_BEGIN = &H100000 'Windows Vista/2008 and higher
    PROCESS_MODE_BACKGROUND_END = &H200000   'Windows Vista/2008 and higher
    REALTIME_PRIORITY_CLASS = &H100
  End Enum

End Enum

Notes:

VB no warnings with option strict = on.

Tips & Tricks:

Please add some!

Sample Code:

  SetPriorityClass(mhHwnd, CType(20, System.IntPtr))    '20 = high !!

SetPriorityClass(mhHwnd, CType(20, System.IntPtr)) '20 = high !!

  SetPriorityClass(Process.GetCurrentProcess.Handle, PriorityClass.PROCESS_MODE_BACKGROUND_BEGIN)

SetPriorityClass(Process.GetCurrentProcess.Handle, PriorityClass.PROCESS_MODE_BACKGROUND_BEGIN)

Alternative Managed API:

System.Diagnostics.Process.PriorityClass (Does not provide PROCESS_MODE_BACKGROUND options)

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions