Compartir a través de


RoleEnvironment.Stopping Event

 

Occurs when a role instance is about to be stopped.

Namespace:   Microsoft.WindowsAzure.ServiceRuntime
Assembly:  Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)

Syntax

public static event EventHandler<RoleEnvironmentStoppingEventArgs> Stopping
public:
event EventHandler<RoleEnvironmentStoppingEventArgs^>^ Stopping {
    static void add(EventHandler<RoleEnvironmentStoppingEventArgs^>^ value);
    static void remove(EventHandler<RoleEnvironmentStoppingEventArgs^>^ value);
}
static member Stopping : IEvent<EventHandler<RoleEnvironmentStoppingEventArgs>,
    RoleEnvironmentStoppingEventArgs>
Public Shared Event Stopping As EventHandler(Of RoleEnvironmentStoppingEventArgs)

Remarks

The Stopping event is used to run code when a role instance is being stopped. This event is raised after the role instance has been taken out of the rotation of the load balancer, but before the OnStop method is called. You can use this event to run code that is required for a role instance to shut down correctly. The Stopping event is not raised when the virtual machine of the role instance is rebooted.

The following code example shows how you can run code when the role instance is being stopped:

public override bool OnStart()
{
   RoleEnvironment.Stopping += RoleEnvironmentStopping;

   return base.OnStart();
} 

private void RoleEnvironmentStopping(object sender, RoleEnvironmentStoppingEventArgs e) 
{
   // Add code that is run when the role instance is being stopped
}

See Also

RoleEnvironmentStoppingEventArgs
RoleEnvironment Class
Microsoft.WindowsAzure.ServiceRuntime Namespace

Return to top