Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to automatically refresh ListView in WPF(periodically after 2 or 5 seconds).

I have 2 PC/Laptops sharing a centralize Sql Server table.

When user of first PC/Laptop update some information, It would be reflected automatically into second PC/Laptop.

When user of first PC/Laptop delete a row, It would be deleted from another as well.

When user insert a row either using GUI or Insert statement of Sql, record would be synchronized for all.

Your reply at the earliest is highly appreciated.

Thanks,
Posted

1 solution

Well, if be honest, it's not a trivial task ;)
Firts thing that comes to my mind is to implement timer , which will be every 2 or 5 seconds gather neccessary information and synchronize your table data.
But in this approach there are a lot of pitfalls, which needs to be workarounded.
Do you eligible to change the data (structure of db)?
In case of yes, i could advise to you, to create a utility table in db , and log all action to that table:
for example at 15:35 user A(PC1) add one row , when timer callback will be invoked it gather all data from that table by specified period of time and performs synchronization.

But this approach also not so smooth, as it requires a lot of query to DB...

Another one, which is more convenient (for my opinion!!!) is to do all kind of this stuff via SignalR framework, if you need more detail about that, let me know and i'll cover it!
 
Share this answer
 
v2
Comments
AbhinandanKumar 26-Dec-12 7:16am    
I have done it using SqlDataReader and a timer, but I am finding some simple and reliable solution.
I am also using two temp tabel for remark of record which is already loaded in ListView.
If Newer comes in table it comes in ListView.
Oleksandr Kulchytskyi 26-Dec-12 7:27am    
"I am also using two temp tabel for remark of record which is already loaded in ListView." - Why so complicated ?)
You can be easily bounded with only 1 table, in which you will write every action which affected table that you are observed.

Approach with SignalR by it nature will be robust and reliable!
But it requires some experience in web.
But one bigger advantage of it, with help of SignalR you can easily get rid of unneccessary stuff with observing temp tables and performing sync.

Lets quickly go through:
Your apps conneced to a SignalR hub, the for CRUD operation they will use this hub.
For example app on PC1 removes record with ID = 1, On Hub side SignalR performs delete operation , after delete was succeed, Hub will notify the rest of the client about delete operation , and all app on differ PF will receive notification abou that and do appropriate actions for sync ListView
AbhinandanKumar 3-Jan-13 2:52am    
Have you any code for that?
send me the code or link please..

no need of explanation..
Oleksandr Kulchytskyi 3-Jan-13 4:30am    
Nope, it's require self implementation and self design.
About SignalR , you can read here https://github.com/SignalR/SignalR/wiki

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