I have been using Asynchronous operations in my WinForms client since the beginning, but only for some operations. When the ExecuteReader
or the ExecuteNonQuery
completes, the callback delegate fires and everything works just fine.
I've basically got two issues:
1) What is the best structure for dealing with this in a real-life system? All the examples I have seen are toy examples where the form handles the operation completion and then opening a datareader on the EndExecuteReader
. Of course, this means that the form is more tightly coupled to the database than you would normally like. And, of course, the form can always easily call .Invoke
on itself. I've set up all my async objects to inherit from a AsyncCtrlBlock<T>
class and have the form and all the callback delegates provided to the constructor of the async objects in my DAL.
2) I am going to re-visit a portion of the program that currently is not async. It makes two calls in series. When the first is complete, part of the model can be populated. When the second is complete, the remaining part of the model can be completed - but only if the first part is already done. What is the best way to structure this? It would be great if the first read can be done and the processing due to the first read be underway while the second is launched, but I don't want the processing of the second read to be started until I know that the processing of the first read's data has been completed.