XK
Implementing a Service that caches requests and then executes on an interval.
@Becquerel that was SOOO useful and it's working brilliantly!
I ended up creating a couple request objects that had metadata required to send to the endpoint, but also included a channel w/ the requested response type.
the service requesters write to the request channel and then await readasync from their provided channels.
Once the delay task finishes on the producer side, I lock the request channel writer so we wait for any more requests to come in until we're finished with this bunch. Perform the request to the end point, and then iterate through the request objects and write back to their provided response channels. Not sure if that approach is the best way to broadcast back to the original requesters but it worked a charm, exactly how I hoped 😄 😄 😄 .
22 replies
Implementing a Service that caches requests and then executes on an interval.
I think the approach is poor and am looking for an existing pattern to solve this I guess.
I'm using ManualResetEvent so once the objects are added to the queue, their background threads are blocked until the TimedQueue fires the batched request and then notifies the threads they may continue with ManualResetEvent.Set.
22 replies
WPF ListBox w/ Header Button IsEnabled Question
I think I've managed something but it's not entirely performant and perhaps there is a better built in way.
@Abhishek_Dev Imagine a viewmodel w/ a CanApprove boolean, which on construction is false, during construction of the object a long running task is executed in a background thread to 'update' the item, when the update is finished CanApprove is 'true.'
I want to enable the button in the ListBox group header only if all the items in the CollectionViewGroup are CanApprove == true.
What I've managed so far is by using binding on the button's IsEnabled property, to the button's datacontext and using a converter to inspect the items in the CollectionViewGroup to see if they are indeed all 'CanApprove' And this worked fine for the initial population of the items but does not refresh.
So to get around that I made a class inherited from ObservableCollection and I subscribe to all the items in the collection's PropertyChanged event. In that event I check if the PropertyChanged event property name == "CanApprove" and if it does I do a check against the collections items to see if they all have "CanApprove" == true. if they do then I update the UI thread with a call to ObservableCollections OnCollectionChanged and provide a NotifyCollectionChangedAction.Reset, which seems to do the trick. It does stall the UI momentarily but unless there is a more performant way to achieve this I think I'm satisfied with it.
6 replies