Thursday, February 17, 2011

How to change the priority of a thread in run time in windows?

I am writing a multi-thread application in windows OS. All threads are runing as services. If I want to change the priority of service in run time, how can I do this? Does windows provide any API?

Many Thanks!

From stackoverflow
  • Yes. There are both Win32 and .NET APIs. Typically, though, normal processes/threads can only reduce their priority. You need to be privileged to elevate your priority.

    Win 32 API

    .NET API

  • The Win32 APIs for setting priority are:

    SetThreadPriority ( http://msdn.microsoft.com/en-us/library/aa394494.aspx ) and

    SetPriorityClass ( http://msdn.microsoft.com/en-us/library/ms686219(VS.85).aspx )

    The SetPriorityClass selects the range of priorities available to a process and the SetThreadPriority sets the relative priority within the class.

    obviously you need the appropriate access rights to change the priority.

0 comments:

Post a Comment