Results 1 to 7 of 7

Thread: #> Putting an App in...

  1. #1

    Thread Starter
    Addicted Member cyberwarpy's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    200

    Question #> Putting an App in...

    Anyone know how to put your app into a high-priority mode...? I know there are process priorities:

    1. Very High
    2. High
    ...

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Use SetThreadPriority api call
    Code:
    Const THREAD_BASE_PRIORITY_IDLE = -15
    Const THREAD_BASE_PRIORITY_LOWRT = 15
    Const THREAD_BASE_PRIORITY_MIN = -2
    Const THREAD_BASE_PRIORITY_MAX = 2
    Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
    Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
    Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
    Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
    Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
    Const THREAD_PRIORITY_NORMAL = 0
    Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
    Const HIGH_PRIORITY_CLASS = &H80
    Const IDLE_PRIORITY_CLASS = &H40
    Const NORMAL_PRIORITY_CLASS = &H20
    Const REALTIME_PRIORITY_CLASS = &H100
    Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
    Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
    Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
    Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
    Private Declare Function GetCurrentThread Lib "kernel32" () As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim hThread As Long, hProcess As Long
        'retrieve the current thread and process
        hThread = GetCurrentThread
        hProcess = GetCurrentProcess
        'set the new thread priority to "lowest"
        SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
        'set the new priority class to "idle"
        SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
        'print some results
        Me.AutoRedraw = True
        Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread))
        Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess))
    End Sub

  3. #3

    Thread Starter
    Addicted Member cyberwarpy's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    200
    So... by using this code.. it will put the whole app and everything that goes along with it... into high CPU priority...?

  4. #4

    Thread Starter
    Addicted Member cyberwarpy's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    200
    Would there also be implications on secure O/S's such as WinNT/2000...? anyone know...?

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    On NT/2000, you need to have requisite permissions. Other than these, I don't think it has any other implications

  6. #6

    Thread Starter
    Addicted Member cyberwarpy's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    200
    then... how would we find out, whether or not it was successfully put on priority...?!? On a system with restrictions or limitations on priorities...

    This wouldn't affect the system, if I put the app in REALTIME mode..?

    Originally posted by amitabh
    On NT/2000, you need to have requisite permissions. Other than these, I don't think it has any other implications

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Trap the return value of the SetThreadPriority api call. It will return success or failure. To know the error, use the GetLastError api call immediately after the api call.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width