Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a background worker thread queue
    primarykey
    data
    text
    <p>I'm trying to implement my first application using the MVVM pattern. I've manged to get most things working, but now I'm facing a problem with the following (IMHO pretty common) scenario:</p> <p>Pressing a <code>Button</code> (View) shall invoke a Method (Model). Using a <code>ICommand</code> (ViewModel) this is pretty easy. But what to do if a time consuming operation has to be executed? </p> <p>My current solution required me to implement a <code>WorkQueue</code> class containing <code>WorkQueueItems</code>. The <code>WorkQueue</code> has a Thread associated with it which executes the <code>WorkQueueItem</code>s. Each <code>WorkQueueItem</code> has a <code>Name</code>, a <code>Status</code> and a <code>Progress</code> which is updated during execution. Each <code>Window</code> has its own <code>WorkQueue</code> - visualized as <code>StatusBar</code>.</p> <p><strong>My problem:</strong> How can a ViewModel find the appropriate <code>WorkQueue</code>? Do I have to pass the <code>WorkQueue</code> to each ViewModel I create (this would be really be annoying)? Or are there other mechanism I could use? </p> <p>I'm not really familiar with <code>RoutedCommand</code>s - tough the basic concept seems to go into this direction. What'd love to see is a solution where I can bind a <code>WorkQueueItem</code> to a Command/Event which then bubbles up to the containing <code>Window</code> where it is added to the <code>Window</code>'s <code>WorkQueue</code>.</p> <p>I also considered making <code>WorkQueue</code> a Singleton - but this only works if I only have one <code>Window</code> at a time.</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.
 

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