This project is read-only.

Warning

The project is deprecated since ArcGIS API for Silverlight 3.2, that supports task-based methods natively.

Project Description

Task-based extension methods for: These methods allow using async/await keywords in Visual Studio 2012/2013.


A list of implemented extension methods can be found here.

Instructions:
Add the following directive to enable extension methods (C#):

using ESRI.ArcGIS.Client.Async;

You need to download and install required APIs or to use the NuGet package ArcGISSilverlight-Core for Silverlight 5. You also need the package Microsoft.Bcl.Async to use async/await keywords in projects targeting .NET Framework 4 (with KB2468871) and Silverlight.
The package ArcGIS.Client.Async will automatically install all required NuGet packages.

Silverlight samples (C#)

Add following directives:

using System.Collections.Generic;
using System.Threading.Tasks;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Async;

Query sample:

private async void QuerySample()
{
    var queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
    var query = new Query { Text = "New", OutFields = { "*" }};
    var result = await queryTask.ExecuteTaskAsync(query);
    // TODO: Process the result
}

Query with a buffer sample:

private async void QueryWithBufferSample()
{
    var sref = new SpatialReference(102100);
            
    // Creating a buffer
    var geometryService = new GeometryService("http://serverapps101.esri.com/arcgis/rest/services/Geometry/GeometryServer");
    var bufferParams = new BufferParameters
    {
        BufferSpatialReference = sref, // TODO: Please use more appropriate SR
        OutSpatialReference = sref,
        Unit = LinearUnit.Meter,
        Distances = { 100 },
        Features = { new Graphic { Geometry = new MapPoint(-9270000, 5247200, sref) } }
    };
    var bufferResult = await geometryService.BufferTaskAsync(bufferParams);
    var buffer = bufferResult.Results.Single();

    // Querying a layer
    var queryTask = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2");
    var query = new Query
    {
        ReturnGeometry = true,
        OutSpatialReference = sref,
        Geometry = buffer.Geometry,
        OutFields = { "*" }
    };
    var queryResult = await queryTask.ExecuteTaskAsync(query);
    var features = queryResult.FeatureSet;

    // TODO: Process the result
}

Concurrent queries sample:

private async void ConcurrentQueriesSample()
{
    // Creating queries
    var query = new Query
    {
        ReturnGeometry = true,
        OutSpatialReference = new SpatialReference(102100),
        Geometry = new MapPoint(-9270000, 5247200, new SpatialReference(102100)),
        OutFields = { "*" }
    };
    
    var queryTask1 = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
    var queryTask2 = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2");

    // Executing queries and adding tasks to a list
    var queries = new List<Task<QueryTaskResult>>
    {
        queryTask1.ExecuteTaskAsync(query),
        queryTask2.ExecuteTaskAsync(query)
    };

    // Waiting for all tasks to complete
    await TaskEx.WhenAll(queries);

    // Looping through query results
    foreach (var task in queries)
    {
        var result = task.Result;
        // TODO: Process the result...
    }
}

Last edited Jan 4, 2014 at 2:53 PM by TDenis, version 50