I am new to the async stuff and am having a lot of problems trying to get this to work:
I am trying to load a large result set from SQL what I want to have happen is when I run the code below:
public async override IEnumerable<DataResult> Read()
{
using (SqlConnection objConn = new SqlConnection(Options.GetConnectionString()))
{
await objConn.OpenAsync();
SqlCommand comm = new SqlCommand(Options.SqlText, objConn);
SqlDataReader reader = await comm.ExecuteReaderAsync();
while (await reader.ReadAsync())
yield return new DataResult { Reader = reader };
}
}
Producer code:
BlockingCollection<DataResult> DataCollection = new BlockingCollection<DataResult>();
var producer = new Producer<DataResult>(() =>
{
using (var sequenceEnum = sourceEngine.Read().GetEnumerator())
{
while (sequenceEnum.MoveNext())
return sequenceEnum.Current;
}
return null;
}, DataCollection);
producer.Start();
That it returns the data as it reads it in record by record to a producer which will store this data into a BlockingCollection for the consumer to consume.
How can I get this code to work for what I am expecting it to do?