New Posts New Posts RSS Feed: How to wait for parallel tasks to complete
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How to wait for parallel tasks to complete

 Post Reply Post Reply
Author
mickan View Drop Down
Newbie
Newbie


Joined: 20-Apr-2011
Location: Atlanta
Posts: 6
Post Options Post Options   Quote mickan Quote  Post ReplyReply Direct Link To This Post Topic: How to wait for parallel tasks to complete
    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).
 
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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
};
Back to Top
mickan View Drop Down
Newbie
Newbie


Joined: 20-Apr-2011
Location: Atlanta
Posts: 6
Post Options Post Options   Quote mickan Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down