65642

How to use SignalR for autorefresh like data

Question:

I've been looking into using SignalR for a while now, and I think I have a good candidate for it.

I have a page which allows users of the system to leave Comments, and at the moment it uses JQuery to periodically refresh the list of comments. I think SignalR would replace this nicely, i.e. if there were two users looking at the list and one wrote a comment, I would like it to appear instantly in the second.

All well and good, I have a <em>sort of</em> template where this works.

<em>However</em>

My system itself can sometimes add automatic notifications to the list - These are put into the database directly by a non-web based application.

How can I get SignalR to see the new information from the database and send it to the users?

Answer1:

In SignalR the <a href="https://github.com/SignalR/SignalR/wiki/Hubs" rel="nofollow">hub</a> is a static part in your application. You can spin up a <a href="https://stackoverflow.com/questions/1416803/system-timers-timer-vs-system-threading-timer" rel="nofollow">System.Threading.Timer</a> in your webapplication to periodically check your database for new notifications and add those to the data used by the hub.

This can even be improved by using a <a href="https://stackoverflow.com/questions/642848/performance-questions-for-sql-cache-dependency" rel="nofollow">SqlCacheDependency</a>.

A subjective side note: <em>I do agree this type of functionality is a very good candidate for SignalR</em>.

Recommend

  • Session value in Javascript
  • collection-repeat with angular component, what is happening?
  • Integrating Django and .Net applications using Single Sign On (SSO)
  • Can I run Robotium tests automatically in parallel on multiple emulators?
  • Android : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG
  • Swift gives “self used before all stored procedures are initialized” error when building child nodes
  • Multiarray with one entry [duplicate]
  • parameterized queries in oursql
  • Sorting by a specific key of a multi dimensional array PHP
  • I can't get setInterval() to work in Javascript
  • How to display callstack line numbers when my program is broken in Rust?
  • Spring Web Flow exception handling
  • Why not Factory pattern for sorting? [closed]
  • Picasso Taking time to load images
  • end daemon processes with multiprocessing module
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • SQL query to group by maximal sets of a column having inner consecutive distances below a threshold
  • (Play 2.5) How do you define json format for type alias of an Option?
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • .NET video play library which allows to change the playback rate?
  • Detecting null parameter in preprocessor macro
  • Can't remove headers after they are sent
  • SAXReader not re-ecape characters
  • Do I need to reset a Perl hash index?
  • How can I sort a a table with VBA with given text condition?
  • Custom Tabgroup Appcelerator
  • Use of this Javascript
  • $wpdb not working in file of WordPress plugin
  • Is it possible to access block's scope in method?
  • Checking free space on FTP server
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Javascript convert timezone issue
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • Arrays break string types in Julia
  • Android Google Maps API OnLocationChanged only called once
  • How does Linux kernel interrupt the application?
  • Does armcc optimizes non-volatile variables with -O0?
  • UserPrincipal.Current returns apppool on IIS
  • git trying to push non-existent file … after clearing cache