0

I would like to develop a C# windows client application that notifies users whenever a new database record is inserted. The server is a remote linux machine with mysql as database engine and it has PHP frontend. As I am new to the C# world I would like some advices on how can I approach this problem. Thank you!

user1584704
  • 27
  • 1
  • 4
  • There are many ways to do this in a distributed system. Perhaps the simplest is to simply send an "UPDATE" message of sorts to the client. Of course, asynchronous I/O would be the best, but I am not familiar enough with C# to be more specific. – RageD Aug 08 '12 at 12:46
  • 1
    Not sure about mysql, but MS SQL Server generates no events of this kind. So you'll probably have to run a background thread checking the database each x seconds/minutes. – ElDog Aug 08 '12 at 12:47
  • Search for *mysql trigger*, this is what you are looking for. @ElDog MS SQL server [has support](http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.server.sqltriggerattribute.aspx) for this from C#. – oleksii Aug 08 '12 at 12:53

1 Answers1

0

I am not familiar with the MySQL API for .NET, but a quick search on the net did not bring up anything better than implementing your own polling logic, for example this SO question: Update C# client whenever database is updated

For this you might add a DateTime colum to all the tables that you need to poll and store the last polling time. This would then make it possible to query for all records that have changed since your last polling interval.

As for the notification of the clients, here I suggest using some kind of message framework. In a homogenous Microsoft environment I would suggest using the Microsoft Message Queue MSMQ. The great thing for the (pure) MSMQ is that the functionality is supported by .NET out of the box. Using it is straight forward and you will quickly find your way into using it.

There are also many other frameworks that are built on top of MSMQ and make your life easier and/ or offer additional features, e.g. like the open source projects MassTransit or NServiceBus. Because you are using both Windows and Linux systems it might be worth to have a look RabbitMQ, which support the most major operating systems.

The advantage of using such a messaging system is that you can configure your applications in a way that neither the message publisher nor the receivers need to know each other. For example, they would not need to have hard coded references (or addresses) to each other.

This gives you great flexibility and scalability, no matter how many clients you have online at any given time.

Community
  • 1
  • 1
Jens H
  • 4,590
  • 2
  • 25
  • 35