다음을 통해 공유


ExecuteAsyncRequest Class

Definition

Contains the data that is needed to execute a message asynchronously.

public ref class ExecuteAsyncRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class ExecuteAsyncRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")>]
type ExecuteAsyncRequest = class
    inherit OrganizationRequest
Public NotInheritable Class ExecuteAsyncRequest
Inherits OrganizationRequest
Inheritance
ExecuteAsyncRequest
Attributes

Examples

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface instance.

This example shows how to use ExecuteAsyncRequest class with the ImportSolutionRequest class

/// <summary>
/// Demonstrates importing a solution asynchronously
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void ExecuteAsyncExample(IOrganizationService service) {

    string ManagedSolutionLocation = @"C:\temp\MetadataBrowser_3_0_0_5_managed.zip";

    byte[] fileBytes = File.ReadAllBytes(ManagedSolutionLocation);

    ImportSolutionRequest importRequest = new() { 
        CustomizationFile = fileBytes
    };

    ExecuteAsyncRequest request = new() { 
        Request = importRequest
    };

    var response = (ExecuteAsyncResponse)service.Execute(request);

    Guid asyncOperationId = response.AsyncJobId;

    // Poll the system job table to get the results
    bool complete = false;
    while (!complete)
    {
        Entity asyncJob = service.Retrieve("asyncoperation", asyncOperationId, new ColumnSet("statecode","statuscode"));
        int statecode = asyncJob.GetAttributeValue<OptionSetValue>("statecode").Value;
        string status = asyncJob.FormattedValues["statuscode"];

        Console.WriteLine(status); // Report the status

        if (statecode == 3)  // Completed
        {
            Console.WriteLine($"Async import job {status}");
            complete = true;
        }
        else {
            Console.WriteLine(status); // Report the status
        }

        Thread.Sleep(1000);
    }
}        

Output

Waiting
Waiting
Waiting For Resources
Waiting For Resources
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
In Progress
Succeeded
Async import job Succeeded

Remarks

Usage

Pass an instance of this class to the Execute(OrganizationRequest) method, which returns an instance of ExecuteAsyncResponse.

Privileges and Access Rights

To perform this action, the caller must have the privileges needed for the message passed in the Request property.

Notes for Callers

There are only three messages that can be executed asynchronously:

Learn to use ExecuteAsync to execute messages asynchronously

Constructors

ExecuteAsyncRequest()

Initializes a new instance of the ExecuteAsyncRequest class.

Properties

ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
Request

Gets or sets the request to execute asynchronously.

RequestId

Gets or sets the ID of the request. Optional.

(Inherited from OrganizationRequest)
RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)

Applies to

See also