3

I have an asp.net c# desktop application which constantly polls for the database data every 5 minutes. This results in lots of load on the server, which in turn reduces its efficiency.

is there any technology in asp.net that supports publish subscribe model independent of database used? I know long polling is one of the alternatives. But I was looking for something which is event driven rather than long poll the data. Any help would be appreciated.

  • Yes. a desktop aplication. It does not involve a browser. – Badarinath Katti Jan 06 '15 at 13:40
  • 1
    You can use messaging technologies to provide publish/subscribe functionalities. Something like ActiveMQ, MSMQ or if you're really rich, Solace. – kha Jan 06 '15 at 13:41
  • There is no built-in technology in asp.net to do this - not sure what you mean by an asp.net desktop application though. Do you mean you're using web services or a WCF service? – Rikalous Jan 06 '15 at 13:44
  • Yes.. i have a web service.. How do i connect to Aspentech? Apart from polling is there an alternative? – Badarinath Katti Jan 29 '15 at 14:34

4 Answers4

3

If you actually are using ASP.net, you can add the SignalR framework to establish a push channel to your desktop application.

On the server side, add the Microsoft.AspNet.SignalR nuget package (Install-Package Microsoft.AspNet.SignalR); on the client, add Microsoft.AspNet.SignalR.Client (Install-Package Microsoft.AspNet.SignalR.Client).

This way, you can notify all your clients whenever an update to the database has been made, like this:

public void AddCustomer(Customer customer)
{
    using (var db = new CustomerContext)
    {
        db.Customers.Add(customer);
        db.SaveChanges();
    }

    var hub = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
    hub(customer.Id);
}
Frank
  • 4,461
  • 13
  • 28
  • ok.. I do not have more clients. Just one desktp app..and a database server.. it has many Dbs to refer. Like Oracle, Aspen tech so on. So concrete comments please. – Badarinath Katti Jan 06 '15 at 13:49
  • Can you tell us how that is an ASP.net application? I don't see how ASP.net comes into play here. If it is a standalone desktop application, my answer doesn't apply. – Frank Jan 06 '15 at 13:50
  • The front end is asp.net c# application. But the data it polls comes from several different DBs. – Badarinath Katti Jan 06 '15 at 13:52
  • 1
    ASP.net is a web technology, not a desktop application platform so I'm still not sure what you mean. – Rikalous Jan 06 '15 at 15:01
  • M sorry.. I just wanted to bring home the point its a c# desktop application :) Yeah.. not asp.net.. – Badarinath Katti Jan 06 '15 at 15:38
1

I think you are looking for something like Reactive Extensions.

http://msdn.microsoft.com/en-gb/data/gg577610.aspx

Under the covers it is all done with some implementation of polling, but the idea is to get the event loop monitoring the polling as efficient as possible.

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
  • This looks promising.. but could not see much of the documentation.. Any more links in this direction? – Badarinath Katti Jan 06 '15 at 13:48
  • http://blogs.msdn.com/b/rxteam/archive/2013/12/13/rxjs-2-2-released.aspx Also look at the SignalR and Messaging answers. They are all valid to the scenario you describe. – Murray Foxcroft Jan 06 '15 at 13:57
  • Thanks! In case of SignalR, Since i have a desktop application, it uses the technique of long polling right? – Badarinath Katti Jan 06 '15 at 14:04
  • SignalR used correctly is very efficient. If you want to avoid hitting the database all the time for many clients, then cache the results on the server. Alternatively, have the server read the DB status once every 5 mins and send a message to all subscribing browsers that the DB is still alive. – Murray Foxcroft Jan 06 '15 at 14:12
  • Hi, i do not have many clients. Just a single desktop aplication. I do not want to constantly poll the database, even once every 5 min is costly, since i have many DBs to poll. Just a Desktop app and many Databases.. – Badarinath Katti Jan 06 '15 at 15:26
0

Well typically you can do this with any messaging service.

Following .net messaging services come in mind:

Margus
  • 19,694
  • 14
  • 55
  • 103
  • All these services use long polling as fallback right? Apart from long polling is there any other alternative for a desktop application? – Badarinath Katti Jan 06 '15 at 14:06
  • @BadarinathKatti If you use Oracle you can create triggers that are executed when something is CRUD (inserted, read, updated, deleted). In case of TSQL, you can create procedures that in addition to their task perform a push. However this is not independent of database. – Margus Jan 06 '15 at 14:45
  • I do not understand. If there are triggers, how will my front end application know ? is there a way that my asp.net app know if some trigger is triggered ? Moreover, i am looking for a particular value inserted.. so CRUD is not covered in that.. – Badarinath Katti Jan 06 '15 at 15:28
0

I've no idea what or how much data you're dealing with here so this answer maybe far too much work unless you have a fairly small amount of data/database tables you're wanting to look at.

Instead of pulling sets of data every 5 minutes, add to your database a Table with a single datetime field. Then create triggers on the tables you want to monitor (on add/edit/delete/whatever). Have it so when the trigger is fired it updates the datetime in the table you created.

Change your desktop application to only pull that datetime value every 5 minutes, keep the value cached somewhere and compare it on each poll, if the datetime changes; your desktop application can then trigger the required data update.

Hugo Yates
  • 2,081
  • 2
  • 26
  • 24
  • Hi.. I have some hundreds of DBs. I need to poll every one of them. Its not on CRUD. I poll for a particular value of a column. If the value of that column is something i am looking for, only then i want the action. – Badarinath Katti Jan 06 '15 at 15:31