in reply to Re^15: how to change process & thread priority on Win32 ?
in thread how to change process & thread priority on Win32 ?
# set first thread for $pid to $hThreadPriority my $pid = 952; my $hThreadPriority = 0; my $retcode; my $hThreadSnap; my $hThread; my $Point; use Data::Dumper; use strict; use Win32::API; Win32::API->Import( 'Kernel32', q[ DWORD GetLastError( ) ] ); $retcode = Win32::API->Import( 'Kernel32', q[ HANDLE CreateToolhelp32Snapshot ( DWORD dwFlags, DWORD th32ProcessID ) ] ); print "import CreateToolhelp32Snapshot code $retcode \n"; use constant TH32CS_SNAPTHREAD => 0x4; $hThreadSnap=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); $retcode = GetLastError(); print "CreateToolhelp32Snapshot error code $retcode \n"; print "hThreadSnap = $hThreadSnap \n"; # typedef for THREADENTRY32 typedef Win32::API::Struct TE32 => qw{ DWORD dwSize; DWORD cntUsage; DWORD th32ThreadID; DWORD th32OwnerProcessID; LONG tpBasePri; LONG tpDeltaPri; DWORD dwFlags; }; $retcode = Win32::API->Import( 'Kernel32', q[ BOOL Thread32First ( HANDLE hSnapshot, LPTE32 lpte)]); print "import thread32first code $retcode \n"; $Point = Win32::API::Struct->new( 'TE32' ); $Point->{dwSize}=28; Thread32First($hThreadSnap, $Point); $retcode = GetLastError(); print "thread32first error $retcode \n"; print "pid = $Point->{th32OwnerProcessID} \n"; $retcode = Win32::API->Import( 'Kernel32', q[ BOOL Thread32Next ( HANDLE hSnapshot, LPTE32 lpte)]); print "import threadnext code $retcode \n"; until ( $Point->{th32OwnerProcessID} == $pid ) { Thread32Next($hThreadSnap, $Point); $retcode = GetLastError(); print "thread32next error $retcode \n"; print "pid = $Point->{th32OwnerProcessID} \n"; } $retcode = Win32::API->Import( 'Kernel32', q[HANDLE OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId ) ] ); print "import openthread code $retcode \n"; use constant THREAD_SET_INFORMATION => 0x0020; use constant THREAD_QUERY_INFORMATION => 0x0040; $hThread = OpenThread( THREAD_SET_INFORMATION|THREAD_QUERY_INFORMATION, 0, $Point->{th32ThreadID} ); $retcode = GetLastError(); print "openthread error code $retcode \n"; $retcode = Win32::API->Import( 'Kernel32', q[BOOL SetThreadPriority( HANDLE hThread, int nPriority ) ] ); print "import openthread code $retcode \n"; SetThreadPriority( $hThread, $hThreadPriority ); $retcode = GetLastError(); print "setthreadpriority error code $retcode \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^17: how to change process & thread priority on Win32 ?
by BrowserUk (Patriarch) on Dec 16, 2005 at 13:58 UTC |