Condividi tramite


Executing logic between PreRender and PreRenderComplete Asyncronously

Most of you are familar with the PageAsyncTask class (https://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask.aspx).  I ran across a scenario that I call the "decision task" and created a "chain pattern" architecture.

Scenario

There is a "controller" custom control that registers an PageAsyncTask that needs information from all the prerender events of all other controls on the page.   This "controller" is the first control in the collection and it needs to do all the processing during the "async" time.   As the normal custom controls prerender events happen, they register data to the "controller'.

Solution or the fun ...

I created a "decision" PageAsyncTask in the prerender of the "controller" custom control.   Inside the "decision" begin task I collected all the data from the other controls prerender registration calls and determined whether I needed to do further processing.   I then proceeded to create additional PageAsyncTasks for the work and then call Page.ExecuteRegisteredAsyncTasks(); to do the work.

The "decision" task really isn't an async task per se so I created a "dummy" IAsyncResult to finish the processing.

Those I have showed think it was inventive and elegant way to implement. If anyone is interested in code snippets let me know and I will try to give some snippets (it is a lot of code to show for a blog post).