I have this shared function :
public static async Task<IList<T>> ExecuteQueryAsync<T>(this CloudTable table, TableQuery<T> query, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken), Action<IList<T>> onProgress = null) where T : ITableEntity, new()
{
var items = new List<T>();
TableContinuationToken token = null;
do
{
TableQuerySegment<T> seg = await table.ExecuteQuerySegmentedAsync<T>(query, token);
token = seg.ContinuationToken;
items.AddRange(seg);
if (onProgress != null) onProgress(items);
} while (token != null && !ct.IsCancellationRequested);
return items;
}
I normally would call this function like this
var query = new TableQuery<DynamicTableEntity>();
var res2 = await myTable.ExecuteQueryAsync(query);
which gives me IList
I'm trying to execute two simultaneous queries, but I'm very confused.
What I did so far
List<Task> TaskList = new List<Task>();
Task task1 = Task.Factory.StartNew( () =>
{
return table1.ExecuteQueryAsync(query);
});
Task task2 = Task.Factory.StartNew( () =>
{
return table2.ExecuteQueryAsync(query2);
});
Task.WaitAll(task1, task2);
var res = ((Task<Task<IList<DynamicTableEntity>>>)task1).Result.Result ;
var res2 = ((Task<Task<IList<DynamicTableEntity>>>)task2).Result.Result ;
It runs fine, but I'm not sure if it is the right approach ?
Any help would be greatly appreciated