MakePriority


Description:
These two subs allow you to easily switch in and out of "Time Critical" priority. When a thread is marked as Time Critical, windows will give all processing time to the thread, which will cause the mouse to stop moving, disc caches not to flush, and so on, so use this with extreme caution.
 
Code:
Option Explicit

Declare Function SetThreadPriority Lib "kernel32" _
   (ByVal hThread As Long, ByVal nPriority As Long) As Long
Declare Function GetCurrentThread Lib "kernel32" () As Long

Public Const THREAD_BASE_PRIORITY_LOWRT = 15
Public Const THREAD_PRIORITY_NORMAL = 0
Public Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT

Public Sub MakePriorityTimeCritical()

    SetThreadPriority GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL

End Sub

Public Sub MakePriorityNormal()

    SetThreadPriority GetCurrentThread, THREAD_PRIORITY_NORMAL

End Sub
 
Sample Usage:
 
    MakePriorityTimeCritical
    'Do something that can't be interrupted
    MakePriorityNormal