Jeremy D
Jeremy D

Reputation: 59

c# Should I use a service or just poll the database

I don't know too much about services so if I am trying to do something they are not intended for please forgive me.

I am trying to wright dispatching software for a family member. They plan on starting with 3 or 4 dispatchers but it may scale in the future. I need the software to constantly (every 5 or 10 seconds at the very least) check and see if a new unhandled call has been placed when not in a call or if they are in a call see if another dispatcher updated the call (due to a call in with additional information).

Which option would be better for the above scenario

A) Have a table in a database that tracks updates to calls/ new calls and poll it every 5 - 10 seconds from every instance of the software.

B) Have a service running on the machine that has the database and have that service take care of all SQL. Create an instance of each call in the service and then just ask the service if there are any changes or unhandled call.

If B, is it possible to create a delegate in the service that the software on another (networked) machine can subscribe to? If so where might I find information on doing that, I could not find anything on google.

Upvotes: 1

Views: 149

Answers (2)

TheGeneral
TheGeneral

Reputation: 81493

This is kind of broad.

However, you can use the following:

  • DB Trigger to watch for inserts etc, then do and fabulous db stuff when triggered.

  • Create a Windows Service that polls, that's not a problem at all.

    • You could even self host a WCF server with a Duplex Contract that other software subscribes to, you could then send notifications etc via that channel.

    • or use SignalR for notification which would work just fine in this situation as well, and is a 5 minute job to get working.

Though, there is lots of approaches here; you really need to do some research to find what suits you most.

Upvotes: 2

Mojtaba Tajik
Mojtaba Tajik

Reputation: 1733

Solution B is better.

If B, is it possible to create a delegate in the service that the software on another (networked) machine can subscribe to? If so where might I find information on doing that, I could not find anything on google.

It depends on your need and project type.

  • You can use SignalR in ASP.Net
  • If you work with sockets you can keep connection alive and store client context in a list and notify theme

Upvotes: 1

Related Questions