Pregunta: | 44412 - DAR PRIORIDAD A UN PROCESO EN LA CPU |
Autor: | Ismael |
Tengo un programa que me transmite tramas por el puerto serie y necesito que sea cada 20 milisegundos al tener que ejecutar varios programas simultaneamente como el mio necesita atender a los sockets el tiempo se alarga de 20 a 100 milisegundos, ¿Hay alguna forma de aumentar la prioridad de mi proceso? ¿Se puede poner mas prioridad en la CPU de este proceso sobre los demás? Se acepta cualquier idea |
Respuesta: | Boluart Bedoya |
MIra aqui te paso parte del código que yo uso para darle prioridades a mi programa en este caso uso GetCurrentProcess para obtener el proceso actual (el de mi programa) si quieres puedes darle cualquier otro proceso que se este ejecutando en ese momento y darle la prioridad que deseas
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() Dim hThread As Long, hProcess As Long hThread = GetCurrentThread hProcess = GetCurrentProcess SetThreadPriority hThread, THREAD_PRIORITY_LOWEST SetPriorityClass hProcess, IDLE_PRIORITY_CLASS Me.AutoRedraw = True Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread)) Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess)) End Sub |