thread.js

来自「JSVM核心类库,收集了JAVA进行JSVM开发必用技术进行归纳,在实际项目应用」· JavaScript 代码 · 共 46 行

JS
46
字号
// Description:	js.lang.Thread 线程类
// Author:	Changhua.Wan
// Version:	2004.03.06.01

_package("js.lang");
_import("js.lang.Object");

function js.lang.Thread(_func, _delay) {

	js.lang.Thread._base.call(this);
	this.func = _func;
	this.delay = 1000;
		if (typeof(_delay) == "number") this.delay = _delay;
	var _handle = null;
	this.start = function() {
		if (_handle != null) return;
		_handle = window.setInterval("window." + this.getUID() + ".run()", this.delay);
	}
	this.sync = false;
	this.run = function() {
		if (this.sync) return;
		this.sync = true;
		if (typeof(this.func) == "function") this.func();
		this.sync = false;
	}
	this.stop = function() {
		window.clearInterval(_handle);
		_handle = null;
	}
}
var _p = js.lang.Thread._extends("js.lang.Object");
var _c = js.lang.Thread;

_c.sleep = function(_ms) {
	var _ss = new Date().getTime();
	while(true) {
		if (new Date().getTime() - _ss > _ms) return;
		try {
			var xmldom = new ActiveXObject("Microsoft.XMLDOM");
			xmldom.async = false;
			xmldom.load("about:blank");
			//TODO ..
		} catch(ex) {}
	}
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?