Windows program update when other users make changes?

Scenario:

  • 4 users run separate instances of the same client program (Winforms), which is associated with the To-Do list with the database.
  • The first user selects an item from the 3rd to-do list.

How to update / update the other 3 user screens to reflect that item # 3 is no longer available?

My thought was a table containing the last print date of a date. The timer will then check every few seconds to see if there have been any changes.

Update1:

Thanks to everyone - there are definitely a number of reliable answers.

I went with a simpler version of the script recommended by Icemanind .

+4
source share
5 answers

Yes. The best way to do this is to implement a push system. Here's how it will work. Whenever someone clicks on the client end, the client sends a message to the server. The server will need to receive this signal, and then the server will send an update message to all clients connected to the server.

I don’t know that your client or server is encoded, but you will want to create a stream on the server that "listens" for incoming messages from clients and, after receiving the message, puts it in the queue, returns to listening to more messages. The second thread on the server should process messages in the queue.

On the client side, you will also need a second thread that listens for incoming messages from the server. Once a message is received, it can process the message and take any action.

A pretty decent client / server programming tutorial and socket can be found here: http://www.codeproject.com/KB/IP/serversocket.aspx

Of course, this is a guide. You will need to change it as you wish.

Hope this makes sense and good luck!

+1
source

As Lucas suggested, you can implement a “Push” style system that, whenever an entity is changed, is “pushed” to other connected users. It can be a little tricky. Working with an outdated system, we deal with this, this is the “Change Number” column, but in fact it can be everything that is updated every time a record changes.

When the user tries to change the object, we query the database to lock the row of this object, where "Change number" reflects the "Change number" that the user currently has.

If the lock is successful, the user can update / delete the object. When they are executed, they “Save / fix” and “Change number” on the object will be increased.

If they can’t get the row lock and the “Change number” is the same, we will show the message that the requested object is being used by another user. If the “Change Number” was different, then the message tells them that they need to update their presentation.

+2
source

You can implement the "Push" system, where when one user updates something, the server sends an update message to all connected clients.

+1
source

I would select the isDirty timestamp / flag mark for items. There is no need to receive all items again and not to create a complex push system. Reread items periodically since the last call.

+1
source

If you use SQL Server as your repository and ADO.NET or something beyond that to access data, you should also check for SQL Dependency.

Basically, you can create a query from a table, and you can instruct SQL Server to notify you if any of the data in this query result changes.

See some related introductory articles:

This requires a bit of initial setup effort, but there is a huge advantage: you will be notified automatically when something that interests you (which is part of the query result set), you can respond to it, There is no messy poll or anything else ....

+1
source

Source: https://habr.com/ru/post/1316574/


All Articles