开发者

WPF: Running tasks without interfering with Animations Performance

Our group read the widely referenced article http://blog.quantumbitdesigns.com/2008/07/22/wpf-cross-thread-collection-binding-part-4-the-grand-solution/ and wondered if any of you could help with our problem:

A team member has a WPF application that has an animation running. The problem is that performing background tasks even on different threads causes the animation to jitter. The issue is that creating a regular thread with a low priority does not help as these tasks eventually have to show the data in the UI controls. For example: We have a control that shows logs of what the application is doing. There is a separate DLL which has a method GetLogs that returns a List of the latest logs. We activate it using a timer and every 500ms the application gets a new list which can contain up to 10000 entries. The log user-control is simply a ListView which is bound to an ObservableCollection. Our requirement is to add each entry from the List we receive to the Observable Collection. We also check that the collection has not exceeded the limit we gave it (say 100000 entries). If it does exceed the limit, we remove the first 10000 entries.

Now this can only be done in the UI dispatcher object so the best close solution is using BackGroundWorker. But this thread does not have a low priority and the priority cannot be set there. We wonder if this will even help since our understanding is that the thread sends the UI elements with Dispatcher.Invoke method.

So this is really parallel for me to add each string to the observable collection with Dispatcher.BeginInvoke(ThreadPriority.Low ……) This slows up the log display plus the animations are still cranky.

Is there is an o开发者_Python百科ut of the box solution for such a common problem(UI performance and background tasks)?


Here is the link to BackgroundWorkerPrioritized Component which is a basic .NET Framework implementation improved with setting thread priority by passing the constructor parameter.

Hope this helps.


I'm not sure what your doing in the background thread, but every time you call Dispatcher.BeginInvoke, your doing something back on the main thread. In your case, every 1/2 second, your doing 10000 things in the main UI thread. Since your updating an ObservableCollection, your also raising a event every time you add/remove something.

In this case, instead of using an observable collection, I'd just use a list. Create the list in the background thread, then bind your listview to that with one Dispatcher.BeginInvoke call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜