ApplicationContext Class

 

Specifies the contextual information about an application thread.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.Windows.Forms.ApplicationContext

type ApplicationContext = 
    class
        interface IDisposable
    end

NameDescription
System_CAPS_pubmethodApplicationContext()

Initializes a new instance of the ApplicationContext class with no context.

System_CAPS_pubmethodApplicationContext(Form)

Initializes a new instance of the ApplicationContext class with the specified Form.

NameDescription
System_CAPS_pubpropertyMainForm

Gets or sets the Form to use as context.

System_CAPS_pubpropertyTag

Gets or sets an object that contains data about the control.

NameDescription
System_CAPS_pubmethodDispose()

Releases all resources used by the ApplicationContext.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the ApplicationContext and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodExitThread()

Terminates the message loop of the thread.

System_CAPS_protmethodExitThreadCore()

Terminates the message loop of the thread.

System_CAPS_protmethodFinalize()

Attempts to free resources and perform other cleanup operations before the application context is reclaimed by garbage collection.(Overrides Object.Finalize().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnMainFormClosed(Object, EventArgs)

Calls ExitThreadCore, which raises the ThreadExit event.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventThreadExit

Occurs when the message loop of the thread should be terminated, by calling ExitThread.

You can use the ApplicationContext class to redefine the circumstances that cause a message loop to exit. By default, the ApplicationContext listens to the Closed event on the application's main Form, then exits the thread's message loop.

The following code example displays two forms and exits the application when both forms are closed. When the application starts and exits, the position of each form is remembered. This example demonstrates how to use an ApplicationContext, along with the Application.Run(context) method, to display multiple forms when the application starts.

The class MyApplicationContext inherits from ApplicationContext and keeps track when each form is closed, and exits the current thread when they both are. The class stores the positions of each form for the user. The form position data is stored in a file titled Appdata.txt that is created in the location determined by UserAppDataPath.

The Main method calls Application.Run(context) to start the application, given the ApplicationContext.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

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

Return to top
Show: