Process.WorkingSet 屬性

定義

警告

This property has been deprecated. Please use System.Diagnostics.Process.WorkingSet64 instead. https://go.microsoft.com/fwlink/?linkid=14202

警告

Process.WorkingSet has been deprecated because the type of the property can't represent all valid results. Use System.Diagnostics.Process.WorkingSet64 instead.

警告

This property has been deprecated. Please use System.Diagnostics.Process.WorkingSet64 instead. http://go.microsoft.com/fwlink/?linkid=14202

警告

Use WorkingSet64

取得相關處理序的實體記憶體使用量 (以位元組為單位)。

public:
 property int WorkingSet { int get(); };
[System.Obsolete("This property has been deprecated.  Please use System.Diagnostics.Process.WorkingSet64 instead.  https://go.microsoft.com/fwlink/?linkid=14202")]
public int WorkingSet { get; }
[System.Obsolete("Process.WorkingSet has been deprecated because the type of the property can't represent all valid results. Use System.Diagnostics.Process.WorkingSet64 instead.")]
public int WorkingSet { get; }
[System.Obsolete("This property has been deprecated.  Please use System.Diagnostics.Process.WorkingSet64 instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public int WorkingSet { get; }
public int WorkingSet { get; }
[System.Obsolete("Use WorkingSet64")]
public int WorkingSet { get; }
[<System.Obsolete("This property has been deprecated.  Please use System.Diagnostics.Process.WorkingSet64 instead.  https://go.microsoft.com/fwlink/?linkid=14202")>]
member this.WorkingSet : int
[<System.Obsolete("Process.WorkingSet has been deprecated because the type of the property can't represent all valid results. Use System.Diagnostics.Process.WorkingSet64 instead.")>]
member this.WorkingSet : int
[<System.Obsolete("This property has been deprecated.  Please use System.Diagnostics.Process.WorkingSet64 instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.WorkingSet : int
member this.WorkingSet : int
[<System.Obsolete("Use WorkingSet64")>]
member this.WorkingSet : int
Public ReadOnly Property WorkingSet As Integer

屬性值

Int32

相關的處理序正在使用的實體記憶體的總量。

屬性

範例

下列範例會啟動記事本的實例。 此範例接著會擷取並顯示相關聯進程的各種屬性。 此範例會偵測進程何時結束,並顯示進程的結束代碼。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   try
   {
      Process^ myProcess;
      myProcess = Process::Start( "NotePad.exe" );
      while (  !myProcess->HasExited )
      {
         Console::WriteLine();
         
         // Get physical memory usage of the associated process.
         Console::WriteLine( "Process's physical memory usage: {0}", myProcess->WorkingSet.ToString() );
         
         // Get base priority of the associated process.
         Console::WriteLine( "Base priority of the associated process: {0}", myProcess->BasePriority.ToString() );
         
         // Get priority class of the associated process.
         Console::WriteLine(  "Priority class of the associated process: {0}", myProcess->PriorityClass );
         
         // Get user processor time for this process.
         Console::WriteLine( "User Processor Time: {0}", myProcess->UserProcessorTime.ToString() );
         
         // Get privileged processor time for this process.
         Console::WriteLine( "Privileged Processor Time: {0}", myProcess->PrivilegedProcessorTime.ToString() );
         
         // Get total processor time for this process.
         Console::WriteLine( "Total Processor Time: {0}", myProcess->TotalProcessorTime.ToString() );
         
         // Invoke overloaded ToString function.
         Console::WriteLine( "Process's Name: {0}", myProcess->ToString() );
         Console::WriteLine( "-------------------------------------" );
         if ( myProcess->Responding )
         {
            Console::WriteLine( "Status:  Responding to user interface" );
            myProcess->Refresh();
         }
         else
         {
            Console::WriteLine( "Status:  Not Responding" );
         }
         Thread::Sleep( 1000 );
      }
      Console::WriteLine();
      Console::WriteLine(  "Process exit code: {0}", myProcess->ExitCode.ToString() );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The following exception was raised:  {0}", e->Message );
   }

}
using System;
using System.Diagnostics;
using System.Threading;

namespace ProcessSample
{
    class MyProcessClass
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = Process.Start("NotePad.exe"))
                {
                    while (!myProcess.HasExited)
                    {
                        Console.WriteLine();

                        Console.WriteLine($"Physical memory usage     : {myProcess.WorkingSet}");
                        Console.WriteLine($"Base priority             : {myProcess.BasePriority}");
                        Console.WriteLine($"Priority class            : {myProcess.PriorityClass}");
                        Console.WriteLine($"User processor time       : {myProcess.UserProcessorTime}");
                        Console.WriteLine($"Privileged processor time : {myProcess.PrivilegedProcessorTime}");
                        Console.WriteLine($"Total processor time      : {myProcess.TotalProcessorTime}");
                        Console.WriteLine($"Process's Name            : {myProcess}");
                        Console.WriteLine("-------------------------------------");

                        if (myProcess.Responding)
                        {
                            Console.WriteLine("Status:  Responding to user interface");
                            myProcess.Refresh();
                        }
                        else
                        {
                            Console.WriteLine("Status:  Not Responding");
                        }

                        Thread.Sleep(1000);
                    }

                    Console.WriteLine();
                    Console.WriteLine($"Process exit code: {myProcess.ExitCode}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"The following exception was raised: {e.Message}");
            }
        }
    }
}
Imports System.Diagnostics
Imports System.Threading

Namespace Process_Sample
    Class MyProcessClass

        Public Shared Sub Main()
            Try

                Using myProcess = Process.Start("NotePad.exe")

                    While Not myProcess.HasExited

                        Console.WriteLine()

                        Console.WriteLine($"Process's physical memory usage          : {myProcess.WorkingSet}")
                        Console.WriteLine($"Base priority of the associated process  : {myProcess.BasePriority}")
                        Console.WriteLine($"Priority class of the associated process : {myProcess.PriorityClass}")
                        Console.WriteLine($"User processor time                      : {myProcess.UserProcessorTime}")
                        Console.WriteLine($"Privileged processor time                : {myProcess.PrivilegedProcessorTime}")
                        Console.WriteLine($"Total processor time                     : {myProcess.TotalProcessorTime}")
                        Console.WriteLine($"Process's name                           : {myProcess}")
                        Console.WriteLine("-------------------------------------")

                        If myProcess.Responding Then
                            Console.WriteLine("Status:  Responding to user interface")
                            myProcess.Refresh()
                        Else
                            Console.WriteLine("Status:  Not Responding")
                        End If
                        Thread.Sleep(1000)
                    End While

                    Console.WriteLine()
                    Console.WriteLine($"Process exit code: {myProcess.ExitCode}")
                End Using

            Catch e As Exception
                Console.WriteLine($"The following exception was raised: {e.Message}")
            End Try
        End Sub
    End Class
End Namespace 'Process_Sample

備註

這個屬性所傳回的值代表進程所使用的最近重新整理工作集記憶體大小,以位元組為單位。 若要取得最新的大小,您必須先呼叫 Refresh() 方法。

進程的工作集是實體 RAM 記憶體中進程目前可見的記憶體分頁集。 這些頁面是常駐的,可供應用程式使用,而不會觸發分頁錯誤。

工作集包含共用和私人資料。 共用資料包含頁面,其中包含進程執行的所有指示,包括進程模組和系統程式庫。

適用於

另請參閱