public int ExecuteQueryAsync(string connectionString, string commandText)
{
// Open a session to Teradata
using (TdConnection cn = new TdConnection(connectionString))
{
cn.Open();
// Execute the command
using (TdCommand cmd = new TdCommand(commandText, cn))
{
CancellationTokenSource cts = new CancellationTokenSource();
// Cancel the command if it doesn't complete in 20 seconds
cts.CancelAfter(20000);
Task<Int32> task;
try
{
task = cmd.ExecuteNonQueryAsync(cts.Token);
}
catch (Exception e)
{
// handle programming errors
}
// perform other tasks
// wait for the Task to complete
try
{
int activityCount = task.Result;
// Return the activity count
return activityCount;
}
catch (AggregateException ae)
{
// handle task execution errors
}
}
}
}