Print Page | Close Window

How to wait for parallel tasks to complete

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3175
Printed Date: 17-Oct-2025 at 2:24am


Topic: How to wait for parallel tasks to complete
Posted By: mickan
Subject: How to wait for parallel tasks to complete
Date Posted: 22-Dec-2011 at 1:03pm
In my initialization routine I want to set off a bunch of startup "tasks" using the parallel coroutine mechanism.  Then I can go away and do other stuff on the UI thread. Great.
 
But, once I'm done with this "other stuff" I mustn't continue with the app until the parallel tasks are completed.  How should I wait (that is, block) at that point?
 
In case you're wondering, the rough working example is loading a bunch of reference data into the EM.  I don't want to query the data in the app until I know its been loaded.  So the plan is to block until it is, having fired off all of the startup tasks and performed other sundry setup (not all of which involving DevForce).
 
 



Replies:
Posted By: DenisK
Date Posted: 22-Dec-2011 at 6:28pm
Hi mickan,

Is it possible to move the query block inside the Coroutine's completed event?

var coop = Coroutine.StartParallel(Tasks);
coop.Completed += (s, args) => {
    //Query the data here
};


Posted By: mickan
Date Posted: 23-Dec-2011 at 8:53am
Denis, thanks for the reply.  In this case I can't do that as the completion code is effecitvely the rest of the application.
 
I just happened to have a chat with Marcel later yesterday and I raised this question.  He suggested running the setup code on a different thread and blocking the UI thread on the completion event once the initialization had proceeded as far as it could go without waiting.
 
I'm still not convinced I understand async sufficiently well, and that perhaps I should be completely restructuring the app initialization as async, but this seems rather drastic, not to mention challenging in a large composite app.


Posted By: DenisK
Date Posted: 28-Dec-2011 at 11:00am
I see. Then I suggest that you continue your discussion with Marcel or one of our Professional Services consultants as I'm afraid this question can lead outside the scope of this forum.



Print Page | Close Window