Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing a WPF application with Prism framework. I have few modules which are interacting with each other through ViewModel or Event aggregator.

I have this two module :

1. Items Lists Module - which is getting real time status of the items from the server. I created a simple background task class which polls the server every sec for the status.

2. Action Button Modules - When user select any of the item. i enabled action buttons in the second module. I used event aggregator to create a custom item selected event for 2nd module.
Now these actions buttons do processing based on user input. Since the communication to the server is involved, i created async methods to keep the UI responsive and allow user to interact with other features of the application.

Now the problem is :
1. While the processing is going on, user can click on other button of the same module. I can avoid interference by simply having a boolean flag and disable button until the processing is going on.

2. User can select the next item from the list (i.e from the 1st module) while the operation for previous item is still in progress.If the user click on any action button this might conflict the previous running process. I always reset the second module when new item is selected but the async methods which is ruining, i have no control on them. I can workaround with taskCancellationSource, but for some reason i am not comfortable using it.

I am looking for a clean viable solution where in i can give user an option to use other actions button without hampering the running process or some way to know that previous action is going on before i allow user to use action buttons for second item. Please note the ViewModel of 2nd module is shared accross all items of 1st Module.

I am looking for a more generic solution which i can use across all my view models.

Looking forward to some great suggestions.

What I have tried:

i have a bool variable IsInprogress in all view model to keep track of the progress and async Wait() method which yields when flag is set to false once the process is completed.

I call this wait() method in all action button to avoid concurrency issues.
Posted

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