[Project_owners] Thread in Mozilla

joe ertaba belaviyo at gmail.com
Wed Jun 17 01:12:26 PDT 2009


Hi,

Here is a sample for Thread in Mozilla,

*<?xml version="1.0"?>*
*<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>*
*<window id="yourwindow" xmlns="
http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">*
*<script type="text/javascript">*
*var main = Components.classes['@
mozilla.org/thread-manager;1'].getService().mainThread;*
*var background = Components.classes['@
mozilla.org/thread-manager;1'].getService().newThread(0);*

*var workingThread = function(threadID, number) {*
*  this.threadID = threadID;*
*  this.number = number;*
*  this.result = 0;*
*};*
*workingThread.prototype = {*
*  run: function() {*
*    try {*
*      // This is where the working thread does its processing work.      *
*      this.result = this.number;*
*      *
*      // When it's done, call back to the main thread to let it know*
*      // we're finished.*
*      *
*      main.dispatch(new mainThread(this.threadID, this.result),*
*        background.DISPATCH_NORMAL);*
*    } catch(err) {*
*      Components.utils.reportError(err);*
*    }*
*  },*
*  *
*  QueryInterface: function(iid) {*
*    if (iid.equals(Components.interfaces.nsIRunnable) ||*
*        iid.equals(Components.interfaces.nsISupports)) {*
*            return this;*
*    }*
*    throw Components.results.NS_ERROR_NO_INTERFACE;*
*  }*
*};*

*var mainThread = function(threadID, result) {*
*  this.threadID = threadID;*
*  this.result = result;*
*};*
*mainThread.prototype = {*
*  run: function() {*
*    try {*
*      // This is where we react to the completion of the working thread.*
*      alert('Thread ' + this.threadID + ' finished with result: ' +
this.result);*
*    } catch(err) {*
*      Components.utils.reportError(err);*
*    }*
*  },*
*  *
*  QueryInterface: function(iid) {*
*    if (iid.equals(Components.interfaces.nsIRunnable) ||*
*        iid.equals(Components.interfaces.nsISupports)) {*
*            return this;*
*    }*
*    throw Components.results.NS_ERROR_NO_INTERFACE;*
*  }*
*};*
*</script>*
*<label id="workingThread" value="workingThread" onclick="*
*    background.dispatch(new workingThread(1, 2),
background.DISPATCH_NORMAL);"/>*
*</window>*



Why when I press "workingThread" more than 3 or 4 times then FF closed?

Any Idea?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mozdev.org/pipermail/project_owners/attachments/20090617/2ea4fc13/attachment.html>


More information about the Project_owners mailing list