Badarinath Katti
Badarinath Katti

Reputation: 33

Alternatives for polling?

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.

Upvotes: 3

Views: 3096

Answers (4)

Hugo Yates
Hugo Yates

Reputation: 2111

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.

Upvotes: 0

Margus
Margus

Reputation: 20028

Well typically you can do this with any messaging service.

Following .net messaging services come in mind:

Upvotes: 0

Frank
Frank

Reputation: 4481

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);
}

Upvotes: 3

Murray Foxcroft
Murray Foxcroft

Reputation: 13745

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.

Upvotes: 1

Related Questions