I am feeling very bad about using lock in my code but now WindowBase's dispatcher is present and I I want to use everywhere.
For example, I use a Multi Thread Singleton WCF service which publishes incidents on PRISM EventAggregator, the payload is irreversible (this is just data) and each thread with a dispatcher this event Can get beautifully, white deadlock in its own sender (not only UI threads, but threads with database calls, threads service calls, threads which allow for logs or slow calls Q other threads, because I do not want to freeze the UI).
But my problem is that this dispatcher is coupled with WPF, so when I use it everywhere, I feel a little guilty, I think the dispatcher is in my mind about the use Was not made.
Is this another dispatcher not applicable with WPF? Or is it okay to abuse it?
Update
One solution for giving me an interface IDispatcher, and an adapter for Wpf Dispatcher, then It will be easy to test! This solution was good for me, because I revised my tests again and now I can use a synchronous despatcher adapter in my tests (thanks to doing this, I do not have to use the WPF dispatcher in my tests is).
It is understandable to use a dispatcher instead of a background player, because I am using a multi publisher / customer pattern (with PRISM), and thank you for every event handler for the dispatcher. Is called on which they subscribe to the event. This means that the only issue where multiple threading issues can occur, is on the payload of my event (I've made them irreversible).
My separate threads do not communicate directly between them, they can only publish and subscribe to the event. In this way, database calls, log calls, service calls, UI calls run on different threads and do not know about each other (they only know about events they subscribe to and publish).
The background worker will understand when I will make some calls from my UI to a repository.
But I hope to find a design without using the background player because I have a habit of using this client / publisher pattern (I think it makes my code more readable). Dispatcher Or background worker), the main issue is that unless your test harness actually has a UI thread
solution 1
use this to work on the UI thread Equally Provides and works in Windows or WPF. Check it out
Solution 2
Think of Dispatcher as just another service, as you use PRISM, you are familiar with services and IOC. It is here that such a How the service can be used:
// UI component not public class MyDomainService: IMyDomainService {Private Readonly IDispatcher _dispatcher; Public MyDomainService (IDispatcher Dispatcher) {_dispatcher = dispatcher; } Private Zero GotResultFromBackgroundThread () {_dispatcher.Dispatch ((= =) DoStuffOnForegroundThread ()); }}
This allows you to move in different implementations for your platform / test.
Here's an example, A and One you will register them with any other service like your IoC container, and they are available for both UI and other services.
Comments
Post a Comment