Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My WPF application comprises of many view models which are loosely depend on each other through Event Manager.

I have a situation where one of the view model receive multiple notifications from other view models.

1. Product module : shows a list of products and the status of each item is changed real time by polling in background service for e.g (Active,Ready,Inactive,Idle, etc)

2. Operation module : It consist of various options (buttons) to carry out certain operation by user on product selection. The view model receive notification from other view models through Event aggregator object.

I receive multiple notification from other view models based on the situation. Some of method is calling web service using async / await and updating the UI. How do i synchronize the method execution if i receive the notifications at the same time or while execution of one operation is going on.


Could you please suggest a better design approach for this.

I am thinking to use semaphore slim in async method and Create single lock object for each view model. if there's any operation is going on the other notification would wait for this object to be release before moving ahead with the execution

What I have tried:

My current solution is :
1. using a bool variable to keep track if any operation is going
2. use lock to avoid concurrency issues.

Though some how i don't feel the solution is robust and could lead to concurrencty issue.
Posted
Updated 18-Sep-16 23:57pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900