This documentation is archived and is not being maintained.

GCNotificationStatus Enumeration

Provides information about the current registration for notification of the next full garbage collection.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<SerializableAttribute> _
Public Enumeration GCNotificationStatus
'Usage
Dim instance As GCNotificationStatus

Member nameDescription
SucceededThe notification was successful and the registration was not canceled.
FailedThe notification failed for any reason.
CanceledThe current registration was canceled by the user.
TimeoutThe time specified by the millisecondsTimeout parameter for either GC.WaitForFullGCApproach(Int32) or GC.WaitForFullGCComplete(Int32) has elapsed.
NotApplicableThis result can be caused by the following: there is no current registration for a garbage collection notification, concurrent garbage collection is enabled, or the time specified for the millisecondsTimeout parameter has expired and no garbage collection notification was obtained. (See the <gcConcurrent> runtime setting for information about how to disable concurrent garbage collection.)

Use the RegisterForFullGCNotification method to register for a full garbage collection notification. Then use the WaitForFullGCApproach method or the WaitForFullGCComplete method to return a GCNotificationStatus enumeration that contains the status of the notification.

The following example obtains a GCNotificationStatus enumeration from the WaitForFullGCApproach method. If the enumeration returns Succeeded, it calls the custom method OnFullGCApproachNotify to perform actions in response to the approaching full garbage collection. This code example is part of a larger example provided for Garbage Collection Notifications topic.

Public Shared Sub WaitForFullGCProc()

    While True 
        ' CheckForNotify is set to true and false in Main. 

        While checkForNotify
            ' Check for a notification of an approaching collection. 
            Dim s As GCNotificationStatus = GC.WaitForFullGCApproach
            If (s = GCNotificationStatus.Succeeded) Then
                Console.WriteLine("GC Notifiction raised.")
                OnFullGCApproachNotify()
            ElseIf (s = GCNotificationStatus.Canceled) Then
                Console.WriteLine("GC Notification cancelled.")
                Exit While 
            Else 
                ' This can occur if a timeout period 
                ' is specified for WaitForFullGCApproach(Timeout)  
                ' or WaitForFullGCComplete(Timeout)   
                ' and the time out period has elapsed. 
                Console.WriteLine("GC Notification not applicable.")
                Exit While 
            End If 

            ' Check for a notification of a completed collection.
            s = GC.WaitForFullGCComplete
            If (s = GCNotificationStatus.Succeeded) Then
                Console.WriteLine("GC Notifiction raised.")
                OnFullGCCompleteEndNotify()
            ElseIf (s = GCNotificationStatus.Canceled) Then
                Console.WriteLine("GC Notification cancelled.")
                Exit While 
            Else 
                ' Could be a time out.
                Console.WriteLine("GC Notification not applicable.")
                Exit While 
            End If 

        End While
        Thread.Sleep(500)
        ' FinalExit is set to true right before   
        ' the main thread cancelled notification. 
        If finalExit Then 
            Exit While 
        End If 

    End While 
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP2, 2.0 SP2
Show: