Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/52a32dbbf42d8249df627b61b93b5107 to your computer and use it in GitHub Desktop.
Save hbulens/52a32dbbf42d8249df627b61b93b5107 to your computer and use it in GitHub Desktop.
var pathToWebWorkerScript = ROOT + 'Scripts/webworker.js';
var worker = new Worker(pathToWebWorkerScript);
worker.onmessage = function (e) {
if (e && e != null) {
// Do work
}
}
var messageParameters = { parameter1: '1', parameter2: '2', };
worker.postMessage(messageParameters);
// Start the worker.
/* This is the code that runs the foreground thread. Firstly, we initialize a new Worker object with 1 parameter: the path to the script that will be run on the background. Note that I use a variable named ROOT to determine the first half of the path. Because I'm using ASP.NET MVC, I thought it would be useful to call a URL helper to make this thing work :*/
var ROOT = '@Url.Content("~/")';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment