Eksportuj (0) Drukuj
Rozwiń wszystko
EN
Ta zawartość nie jest dostępna w wymaganym języku. Wersja w języku angielskim znajduje się tutaj.

Use the RoleEnvironment.Changing Event

Updated: May 9, 2014

The Changing event enables you to manage how a role instance responds to a configuration change. By using the Changing event, an instance can respond to a configuration change in one of the following ways:

  • The instance can accept the configuration change while it is running, without going offline.

  • The instance can cancel the Changing event, in which case Azure takes the instance offline, applies the configuration change, and then brings the instance back online.

By cancelling the Changing event, you can ensure that the instance proceeds through an orderly shutdown sequence and is taken offline before the configuration change is applied. During the shutdown process, Azure raises the Stopping event, and then runs any code in the OnStop method.

noteNote
You have a limited amount of time to accept or cancel the Changing event. Make sure your event handler can return in a timely manner.

You may want to cancel the Changing event if:

  • Your role instance does not support configuration changes while it is running, and requires recycling in order to apply the change.

  • Your role instance is performing work that should not be disrupted by a configuration change, and needs to proceed through the shutdown sequence before applying the change.

The RoleEnvironmentChangingEventArgs class provides a Changes property that returns a collection of the configuration changes that are about to be applied to the instance. Objects in this collection can be one of the following types:

noteNote
You can see the name of the configuration setting that is changing, but you cannot access the new value until the Changed event is raised.

  1. Open the source file where you are handling configuration changes.

  2. Ensure that the project references the Microsoft.WindowsAzure.ServiceRuntime.dll file and that the following using statement is added to the file:

    using Microsoft.WindowsAzure.ServiceRuntime;
    
  3. Add the following code to the OnStart method to specify the event handler:

    
    public override bool OnStart()
    {
       RoleEnvironment.Changing += RoleEnvironmentChanging;
                
       return base.OnStart();
    }
    
  4. Add the following event handler method to the source file:

    
    private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
    {
       // Add code for handling changes
    }
    
  5. Save the file.

See Also

Pokaż:
© 2014 Microsoft