Last active
December 19, 2015 04:49
-
-
Save davidfowl/5899632 to your computer and use it in GitHub Desktop.
Stress harness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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