Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Dispatcher is not quite as simple as it sounds. Using a dispatcher means the code will be executed on the same thread which created the containing object, but that is not necessarily the UI thread. Make sure the worker_DoWork method is defined in an actual UI element that appears on the screen (which is just an easy way to eliminate elements created by background threads).</p> <p>Really, looking at your code, I'm not sure why you're using a background worker at all. This looks like it will actually be slower, because of the constant dispatching to the UI thread. Instead, I think your better option would be to just put the long-running portions in a task, and update the UI on a single callback. For example, in your code it looks like the only thing that is actually too slow for the UI thread might be the FileSearcher call. That would be easy enough to put in a background task which returns the number of results found.</p> <p>As for the problem on FileSearcher, your method definitions don't match up. The method you posted takes just a path and the out int, but when you call it you pass 4 parameters. Without seeing the overload you're actually calling it's tough to guess what's going wrong.</p> <p>EDIT: Let me back up a little more. Your root problem is just that WPF doesn't support binding to a collection which is modified from a background thread. That's the reason for all of the dispatching and other complicated code there. My original suggestion (a single task for the long work) was one way to work around the problem. but you can probably do even better using the <a href="http://blog.quantumbitdesigns.com/2008/07/22/wpf-cross-thread-collection-binding-part-4-the-grand-solution/" rel="nofollow">ObservableList class</a>. This lets you update the collection from the background thread, and automatically notifies the UI without having to use a dispatcher. That is likely to make most of the complicated threading issues go away. I'd recommend reading through the first three articles there for reference, too, there's a lot of good information there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload