AsyncParallelTask
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=2195
Printed Date: 14-May-2025 at 10:44pm
Topic: AsyncParallelTask
Posted By: dpollot44
Subject: AsyncParallelTask
Date 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?
|
Replies:
Posted By: dpollot44
Date 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.
|
|