New Posts New Posts RSS Feed: AsyncParallelTask
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

AsyncParallelTask

 Post Reply Post Reply
Author
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Topic: AsyncParallelTask
    Posted: 27-Sep-2010 at 8:29am
I'm running DevForce 6.0.4.
I have a WPF Browser app that needs a bunch of data loaded... I want the user to be able to navigate around the app a bit before all of this data has finished loading (or at least give them some visual cues as to what's going on and why the app isn't responding).  Naturally the AsyncParallelTask seemed like the best avenue.

I've got a simple progress wheel with a status message on the page, and an application context class with a property notifying the application of a busy/non busy state.  I'm familiar with Microsoft's parallel task library and I've tested the app out with to be sure there's nothing wrong with the UI/ViewModel...

            AppContext.Current().Status.Message = "Loading...";
            AppContext.Current().IsBusy = true;
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                int j = 0;
                for (int i = 0; i < 1000000000; i++)
                    j = i;
               
                Dispatcher.BeginInvoke(new Action(() => { AppContext.Current().IsBusy = false; }));

            });


That works fine, UI is responsive, progress wheel spins, everyone is happy, except that applications rarely need only count
to a billion - there are no cross thread problems there.

Enter async queries using the AsyncParallelTask object:

Context.Status.Message = "Loading...";
Context.IsBusy = true;
AsyncParallelTask.Create()
                .AddAsyncQuery("ClientIds", x => somequery, (completed) =>{
                    completed.Results.ToList().ForEach(id => Context.ClientIds.Add(id));
                })
                .AddAsyncQuery("AccountManagers", x => somequery, (completed) => {
                    completed.Results.ToList().ForEach(am => Context.AccountManagers.Add(am));
                })
                .AddAsyncQuery("Reconcilers", x => somequery, (completed) => {
                    completed.Results.ToList().ForEach(r => Context.Reconcilers.Add(r));
                }) .... and so on ....
                .Execute(args =>
                {
                    Context.IsBusy = false;
                });


Running this causes the UI to hang until everything is done.
What am I doing wrong??  What's the point of having parallel async queries that still lock up my UI?


Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 27-Sep-2010 at 11:47am
I think that populating the observable collections after each parallel async task is what's blocking the UI thread.
I guess there's really nothing you can do about that...

If I want to use the completion map, what should the args be casted to?  At least that way, I can keep the UI thread free until everything has been retrieved.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down