共用方式為


Role.Instances Property

 

Gets the collection of instances for the role.

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

Syntax

public abstract ReadOnlyCollection<RoleInstance> Instances { get; internal set; }
public:
property ReadOnlyCollection<RoleInstance^>^ Instances {
    virtual ReadOnlyCollection<RoleInstance^>^ get() abstract;
    internal: virtual void set(ReadOnlyCollection<RoleInstance^>^ value) abstract;
}
abstract Instances : ReadOnlyCollection<RoleInstance> with get, internal set
Public MustOverride Property Instances As ReadOnlyCollection(Of RoleInstance)
    Get
    Friend Set
End Property

Property Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<RoleInstance>

Type: System.Collections.ObjectModel.ReadOnlyCollection

A ReadOnlyCollection<T> that contains the instance objects for the role.

Remarks

The number of instances of a role to be deployed to Windows Azure is specified in the ServiceConfiguration.cscfg file. For more information about configuring the hosted service, see Windows Azure Service Configuration Schema.

The following code example shows how to retrieve the identifier for each role instance in the collection:

foreach (RoleInstance roleInst in RoleEnvironment.CurrentRoleInstance.Role.Instances)    
{
   Trace.WriteLine("Instance ID: " + roleInst.Id);    
}

You can change the number of role instances that are running by changing the instances count in the ServiceConfiguration.csfg file. For more information about changing the instance count, see How to Scale Applications by Increasing or Decreasing the Number of Role Instances.

Note

At least one internal endpoint must be defined for a role to enable instances to be known at runtime. For more information about defining internal endpoints, see How to Define Internal Endpoints for a Role.

See Also

RoleEnvironment
RoleInstance
Role Class
Microsoft.WindowsAzure.ServiceRuntime Namespace

Return to top