Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
  • None
User Action:
  • None
.NET Framework Class Library

EventArgs Class

Represents the base class for classes that contain event data, and provides a value to use for events that do not include event data.

Namespace:  System
Assemblies:   System.Runtime (in System.Runtime.dll)
  mscorlib (in mscorlib.dll)
Public Class EventArgs

The EventArgs type exposes the following members.

  Name Description
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps EventArgs Initializes a new instance of the EventArgs class.
Top
  Name Description
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Empty Provides a value to use with events that do not have event data.
Top

This class serves as the base class for all classes that represent event data. For example, the System.AssemblyLoadEventArgs class derives from EventArgs and is used to hold the data for assembly load events. To create a custom event data class, create a class that derives from the EventArgs class and provide the properties to store the necessary data. The name of your custom event data class should end with EventArgs.

To pass an object that does not contain any data, use the Empty field.

For more information about events, see the Handling and Raising Events article.

The following example shows a custom event data class named ThresholdReachedEventArgs that derives from the EventArgs class. An instance of the event data class is passed to the event handler for the ThresholdReached event.

Module Module1

    Sub Main()
        Dim c As Counter = New Counter(New Random().Next(10))
        AddHandler c.ThresholdReached, AddressOf c_ThresholdReached

        Console.WriteLine("press 'a' key to increase total")
        While Console.ReadKey(True).KeyChar = "a"
            Console.WriteLine("adding one")
            c.Add(1)
        End While 
    End Sub 

    Sub c_ThresholdReached(sender As Object, e As ThresholdReachedEventArgs)
        Console.WriteLine("The threshold of {0} was reached at {1}.", e.Threshold, e.TimeReached)
        Environment.Exit(0)
    End Sub 
End Module 

Class Counter
    Private threshold As Integer 
    Private total As Integer 

    Public Sub New(passedThreshold As Integer)
        threshold = passedThreshold
    End Sub 

    Public Sub Add(x As Integer)
        total = total + x
        If (total >= threshold) Then 
            Dim args As ThresholdReachedEventArgs = New ThresholdReachedEventArgs()
            args.Threshold = threshold
            args.TimeReached = DateTime.Now
            OnThresholdReached(args)
        End If 
    End Sub 

    Protected Overridable Sub OnThresholdReached(e As ThresholdReachedEventArgs)
        RaiseEvent ThresholdReached(Me, e)
    End Sub 

    Public Event ThresholdReached As EventHandler(Of ThresholdReachedEventArgs)
End Class 

Class ThresholdReachedEventArgs
    Inherits EventArgs

    Public Property Threshold As Integer 
    Public Property TimeReached As DateTime
End Class

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.