IDSDataServiceAsync GetDataAsync Method (DSDataRequest)DSWS API (.NET)

[This is preliminary documentation and is subject to change.]

GetData asynchronously using the task based asynchronous pattern

Namespace: Datastream.DswsApi
Assembly: Datastream.DswsApi.NET4.0 (in Datastream.DswsApi.NET4.0.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax

public Task<DSDataResponse> GetDataAsync(
	DSDataRequest request
)

Return Value

The task object
Remarks

This method helps to retrieve data asynchronously using the task based pattern. For using the IAsyncResult based pattern use the BeginXXX methods.
Examples

// Create a data request 
var request = new DSDataRequest()
{
    Instrument = new DSInstrument("VOD"),
    DataTypes = new DSDataTypes("PL", "PH"),
    Date = new DSTimeSeriesDate(DSDateType.Relative(-30), DSDateType.Relative(-10), DSDateFrequency.Daily),
};


// Start the async task 
var task = DSClient.DataServiceAsync.GetDataAsync(request);

// Make sure when the task completes, we process the result 
// If you want to show results in UI, make sure you pass a valid sync context to TPL
task.ContinueWith(t =>
{
    // After the task is completed, access the results  
    double[] dt1Values = t.Result["PL"]["VOD"].GetValue<double[]>();
    double[] dt2Values = t.Result["PH"]["VOD"].GetValue<double[]>();

    // In case you need to show the results in a UI... 
    // Note that .NET TPL will preserve the synchronization context 
    ShowResultsInUI();

}, TaskScheduler.FromCurrentSynchronizationContext());


// Optionally wait for the task to complete - usually this is not done by a UI application 
// task.Wait();
Version Information

.NET API Framework

Supported in: 4.1
See Also