Process.BasePriority 属性

获取关联进程的基本优先级。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public ReadOnly Property BasePriority As Integer
用法
Dim instance As Process
Dim value As Integer

value = instance.BasePriority
public int BasePriority { get; }
public:
property int BasePriority {
    int get ();
}
/** @property */
public int get_BasePriority ()
public function get BasePriority () : int

属性值

基本优先级,它从关联进程的 PriorityClass 计算。

异常

异常类型 条件

PlatformNotSupportedException

该平台为 Windows 98 或 Windows Millennium Edition (Windows Me);如果将 ProcessStartInfo.UseShellExecute 属性设置为 false,则可以在 Windows 98 和 Windows Me 上访问此属性。

InvalidOperationException

该进程已经退出。

- 或 -

该进程尚未启动,所以没有进程 ID。

备注

进程的 BasePriority 是关联进程内创建的线程起始优先级。可以通过“系统监视器优先级基数”计数器查看有关基本优先级的信息。

在需要将某个进程放到其他进程前时,操作系统可基于运行时间或其他提升来更改基本优先级。

BasePriority 属性使您可以查看分配给进程的起始优先级。但是,因为它是只读属性,所以您不能使用 BasePriority 来设置进程的优先级。若要更改优先级,请使用 PriorityClass 属性。BasePriority 可通过系统监视器查看,而 PriorityClass 则不能。BasePriorityPriorityClass 都可以编程方式进行查看。下表展示 BasePriority 值和 PriorityClass 值之间的关系。

BasePriority

PriorityClass

4

Idle

8

Normal

13

High

24

RealTime

Windows 98, Windows Millennium Edition 平台说明: 如果在启动进程时 ProcessStartInfo.UseShellExecute 设置为 true,则此属性在此平台上不可用。

示例

下面的示例启动一个记事本实例。该示例然后检索并显示关联进程的各种属性。该示例检测该进程何时退出,并显示该进程的退出代码。

Imports System
Imports System.Diagnostics

Namespace ProcessSample
   Class ProcessMonitorSample

      Public Shared Sub Main()

         ' Define variables to track the peak
         ' memory usage of the process.
         Dim peakPagedMem As Long = 0
         Dim peakWorkingSet As Long = 0
         Dim peakVirtualMem As Long = 0

         Dim myProcess As Process = Nothing

         Try

            ' Start the process.
            myProcess = Process.Start("NotePad.exe")

            ' Display process statistics until
            ' the user closes the program.
            Do

                If Not myProcess.HasExited Then

                    ' Refresh the current process property values.
                    myProcess.Refresh()

                    Console.WriteLine()
                        
                    ' Display current process statistics.

                    Console.WriteLine("{0} -", myProcess.ToString())
                    Console.WriteLine("-------------------------------------")

                    Console.WriteLine("  physical memory usage: {0}", _
                         myProcess.WorkingSet64)
                    Console.WriteLine("  base priority: {0}", _
                         myProcess.BasePriority)
                    Console.WriteLine("  priority class: {0}", _
                         myProcess.PriorityClass)
                    Console.WriteLine("  user processor time: {0}", _
                         myProcess.UserProcessorTime)
                    Console.WriteLine("  privileged processor time: {0}", _
                         myProcess.PrivilegedProcessorTime)
                    Console.WriteLine("  total processor time: {0}", _
                         myProcess.TotalProcessorTime)

                    ' Update the values for the overall peak memory statistics.
                    peakPagedMem = myProcess.PeakPagedMemorySize64
                    peakVirtualMem = myProcess.PeakVirtualMemorySize64
                    peakWorkingSet = myProcess.PeakWorkingSet64

                    If myProcess.Responding Then
                        Console.WriteLine("Status = Running")
                    Else
                        Console.WriteLine("Status = Not Responding")
                    End If
                End If
            Loop While Not myProcess.WaitForExit(1000)

            Console.WriteLine()
            Console.WriteLine("Process exit code: {0}", myProcess.ExitCode)

            ' Display peak memory statistics for the process.
            Console.WriteLine("Peak physical memory usage of the process: {0}", _
                peakWorkingSet)
            Console.WriteLine("Peak paged memory usage of the process: {0}", _
                peakPagedMem)
            Console.WriteLine("Peak virtual memory usage of the process: {0}", _
                peakVirtualMem)

         Finally
            If Not myProcess Is Nothing Then
                myProcess.Close
            End If
         End Try
      End Sub 'Main
   End Class 
End Namespace 
using System;
using System.Diagnostics;

namespace ProcessSample
{
    class ProcessMonitorSample
    {
        public static void Main()
        {

            // Define variables to track the peak
            // memory usage of the process.
            long peakPagedMem = 0, 
                peakWorkingSet = 0, 
                peakVirtualMem = 0;

            Process myProcess = null;

            try 
            {
                // Start the process.
                myProcess = Process.Start("NotePad.exe");
    
                // Display the process statistics until
                // the user closes the program.
                do 
                {
                    if (!myProcess.HasExited)
                    {
                        // Refresh the current process property values.
                        myProcess.Refresh();

                        Console.WriteLine();
                        
                        // Display current process statistics.

                        Console.WriteLine("{0} -", myProcess.ToString());
                        Console.WriteLine("-------------------------------------");

                        Console.WriteLine("  physical memory usage: {0}",
                            myProcess.WorkingSet64);
                        Console.WriteLine("  base priority: {0}",
                            myProcess.BasePriority);
                        Console.WriteLine("  priority class: {0}",
                            myProcess.PriorityClass);
                        Console.WriteLine("  user processor time: {0}",
                            myProcess.UserProcessorTime);
                        Console.WriteLine("  privileged processor time: {0}",
                            myProcess.PrivilegedProcessorTime);
                        Console.WriteLine("  total processor time: {0}",
                            myProcess.TotalProcessorTime);

                        // Update the values for the overall peak memory statistics.
                        peakPagedMem = myProcess.PeakPagedMemorySize64;
                        peakVirtualMem = myProcess.PeakVirtualMemorySize64;
                        peakWorkingSet = myProcess.PeakWorkingSet64;

                        if (myProcess.Responding)
                        {
                            Console.WriteLine("Status = Running");
                        }
                        else
                        {
                            Console.WriteLine("Status = Not Responding");
                        }
                    }
                }
                while (!myProcess.WaitForExit(1000));


                Console.WriteLine();
                Console.WriteLine("Process exit code: {0}", 
                    myProcess.ExitCode);
            
                // Display peak memory statistics for the process.
                Console.WriteLine("Peak physical memory usage of the process: {0}",
                    peakWorkingSet);
                Console.WriteLine("Peak paged memory usage of the process: {0}",
                    peakPagedMem);
                Console.WriteLine("Peak virtual memory usage of the process: {0}",
                    peakVirtualMem);

            } 
            finally
            {
                if (myProcess != null)
                {
                    myProcess.Close();
                }
            }
        }

    }
}
#using <system.dll>

using namespace System;
using namespace System::Diagnostics;
int main()
{
   
   // Define variables to track the peak
   // memory usage of the process.
   _int64 peakPagedMem = 0,peakWorkingSet = 0,peakVirtualMem = 0;
   Process^ myProcess = nullptr;
   try
   {
      
      // Start the process.
      myProcess = Process::Start( "NotePad.exe" );
      
      // Display the process statistics until
      // the user closes the program.
      do
      {
         if (  !myProcess->HasExited )
         {
            
            // Refresh the current process property values.
            myProcess->Refresh();
            Console::WriteLine();
            
            // Display current process statistics.
            Console::WriteLine( "{0} -", myProcess );
            Console::WriteLine( "-------------------------------------" );
            Console::WriteLine( "  physical memory usage: {0}", myProcess->WorkingSet64 );
            Console::WriteLine( "  base priority: {0}", myProcess->BasePriority );
            Console::WriteLine( "  priority class: {0}", myProcess->PriorityClass );
            Console::WriteLine( "  user processor time: {0}", myProcess->UserProcessorTime );
            Console::WriteLine( "  privileged processor time: {0}", myProcess->PrivilegedProcessorTime );
            Console::WriteLine( "  total processor time: {0}", myProcess->TotalProcessorTime );
            
            // Update the values for the overall peak memory statistics.
            peakPagedMem = myProcess->PeakPagedMemorySize64;
            peakVirtualMem = myProcess->PeakVirtualMemorySize64;
            peakWorkingSet = myProcess->PeakWorkingSet64;
            if ( myProcess->Responding )
            {
               Console::WriteLine( "Status = Running" );
            }
            else
            {
               Console::WriteLine( "Status = Not Responding" );
            }
         }
      }
      while (  !myProcess->WaitForExit( 1000 ) );
      Console::WriteLine();
      Console::WriteLine( "Process exit code: {0}", myProcess->ExitCode );
      
      // Display peak memory statistics for the process.
      Console::WriteLine( "Peak physical memory usage of the process: {0}", peakWorkingSet );
      Console::WriteLine( "Peak paged memory usage of the process: {0}", peakPagedMem );
      Console::WriteLine( "Peak virtual memory usage of the process: {0}", peakVirtualMem );
   }
   finally
   {
      if ( myProcess != nullptr )
      {
         myProcess->Close();
      }
   }

}

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Process 类
Process 成员
System.Diagnostics 命名空间
PriorityClass
ProcessPriorityClass
ThreadPriorityLevel