I have the following method :
private void GetHistoricalRawDataFromTextFiles(MessageHeader header, HistoricalRawDataFromTextFileSubscriptionDto dto)
{
var computeInstance = GetComputeInstance(dto.SubscriberId, dto.ComputeInstanceId);
var task = computeInstance.GetHistoricalRawDataFromTextFiles(dto, progress => SendProgress(header.Sender, progress));
task.ContinueWith(myTask =>
{
dto.TimeSeries = myTask.Result;
Messenger.SendTo(SubscriberId, header.Sender, MessageType.Reply, MessageTopic.HistoricalRawDataFromTextFiles, dto);
});
}
Method computeInstance.GetHistoricalRawDataFromTextFiles
returns a Task<List<string>>
and my question is
- whether this is the correct way to pass
header
anddto
into the lambda expression and task continuations. It is important that theheader
anddto
instance values are captured within the lambda expression and task continuation at the time the outer method is called. The same method may be called again before the task from the previous call completes.