views:

329

answers:

1

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.

A: 

regarding 2)

make the first phase of your model populating asynchronous. you will have something like that


FisrtCall();
AsyncResult arPh1 = BeginPhaseOne(); //use results from first call
SecondCall();
EndPhaseOne(arPh1); //wait until phase one is finished
PhaseTwo(); //proceed to phase two

ULysses
To get the bounty, I'm going to want to see a real example code, or a link to an article with a real example which 1) doesn't process the events in a form and 2) shows how to queue two requests but only process the second after the first request has completed and has been processed (and the first request results be processed even while the second is still pending)
Cade Roux