Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active December 19, 2015 04:49
Show Gist options
  • Save davidfowl/5899632 to your computer and use it in GitHub Desktop.
Save davidfowl/5899632 to your computer and use it in GitHub Desktop.
Stress harness
/// <reference path="Scripts/jquery-1.6.4.min.js" />
/// <reference path="Scripts/jquery.signalR-1.1.2.js" />
$(function () {
var connection = $.hubConnection(),
hub = connection.createHubProxy('harness');
hub.on('update', function (data) {
console.log(data);
});
connection.disconnected(function () {
setTimeout(function () {
connection.start();
},
500);
});
connection.logging = true;
connection.start();
});
using System;
using System.Diagnostics;
using System.Threading;
using System.Web.Routing;
using Microsoft.AspNet.SignalR;
namespace CrazyHarness
{
public class Harness : Hub
{
}
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
RunBackgroundThread();
}
private static void RunBackgroundThread()
{
ThreadPool.QueueUserWorkItem(_ =>
{
var hubContext = GlobalHost.ConnectionManager.GetHubContext<Harness>();
while (true)
{
try
{
hubContext.Clients.All.update(DateTime.Now.ToString());
}
catch (Exception ex)
{
Trace.TraceError("SignalR error thrown in: {0}", ex);
}
Thread.Sleep(10000);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment