1 | #Region "Microsoft.VisualBasic::70b1299aaf4649ed5572809387bb9ae1, Microsoft.VisualBasic.Core\ApplicationServices\Tools\Win32\PriorityClass.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module PriorityClass |
35 | ' |
36 | ' Function: PriorityClass |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Namespace Win32 |
44 | |
45 | ''' <summary> |
46 | ''' Process priority class helper. |
47 | ''' </summary> |
48 | Public Module PriorityClass |
49 | |
50 | ''' <summary> |
51 | ''' 当前进程句柄 |
52 | ''' </summary> |
53 | ''' <returns></returns> |
54 | Public Declare Function GetCurrentProcess Lib "kernel32" () As Integer |
55 | Public Declare Function SetPriorityClass Lib "kernel32" (hProcess As Integer, dwPriorityClass As Integer) As Integer |
56 | |
57 | ''' <summary> |
58 | ''' 新进程应该有非常低的优先级——只有在系统空闲的时候才能运行。基本值是4 |
59 | ''' </summary> |
60 | Public Const IDLE_PRIORITY_CLASS = &H40 |
61 | ''' <summary> |
62 | ''' 新进程有非常高的优先级,它优先于大多数应用程序。基本值是13。注意尽量避免采用这个优先级 |
63 | ''' </summary> |
64 | Public Const HIGH_PRIORITY_CLASS = &H80 |
65 | ''' <summary> |
66 | ''' 标准优先级。如进程位于前台,则基本值是9;如在后台,则优先值是7 |
67 | ''' </summary> |
68 | Public Const NORMAL_PRIORITY_CLASS = &H20 |
69 | |
70 | ''' <summary> |
71 | ''' Set Priority Class for current process. |
72 | ''' </summary> |
73 | ''' <param name="priority"><see cref="IDLE_PRIORITY_CLASS"/>, <see cref="HIGH_PRIORITY_CLASS"/>, <see cref="NORMAL_PRIORITY_CLASS"/></param> |
74 | ''' <returns></returns> |
75 | Public Function PriorityClass(priority As Integer) As Boolean |
76 | Dim CurrentProcesshWnd As Integer = GetCurrentProcess |
77 | |
78 | If (SetPriorityClass(CurrentProcesshWnd, priority) = 0) Then |
79 | Return False |
80 | Else |
81 | Return True |
82 | End If |
83 | End Function |
84 | End Module |
85 | End Namespace |