进度表和 XPCOM
我正在开发一个 Firefox 扩展,它使用 PyXPCOM 来运行进程。我想要一个进度表,在进程启动时显示并向用户提供反馈。
在 javascript 中,我调用了线程管理器来在 Python 中运行该进程:
var threadManager = Components.classes["@mozilla.org/thread-manager;1"].getService();
var background = threadManager.newThread(0);
background.dispatch(obj, background.DISPATCH_NORMAL);
所以我想知道是否有一种方法可以检查线程何时开始其工作以及何时完成。这帮助我用 JavaScript 控制我的进度表!
如果有人对实施进度表有更好的想法,请告诉我:)
谢谢
I'm developing a Firefox extension that uses PyXPCOM to run a process. I would like to have a progress meter that is shown when the process is started and gives feedback to the user.
In the javascript I have called the Thread Manager to run the process in Python:
var threadManager = Components.classes["@mozilla.org/thread-manager;1"].getService();
var background = threadManager.newThread(0);
background.dispatch(obj, background.DISPATCH_NORMAL);
so I wonder whether there is a way to check when the thread starts its job and when it finishes. This helps me to control my progress meter in javascript!
If anyone has better idea in implementing the progress meter, please let me know :)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不应该直接从 JavaScript 创建新线程 - 这有很多线程安全问题,据我所知,这个功能在 Firefox 4 中不再可用。替代者是 chrome 工作人员: https://developer.mozilla.org/en/DOM/ChromeWorker。因此,您将像这样创建您的工作人员:
您还希望从工作人员接收消息(例如进度通知)。
当然,工作人员本身需要通过 postMessage 函数向您发送进度通知,例如:
You shouldn't be creating new threads from JavaScript directly - this has lots of thread safety issues and from all I know this functionality is no longer available in Firefox 4. The replacement are chrome workers: https://developer.mozilla.org/en/DOM/ChromeWorker. So you would create your worker like this:
You would also want to receive messages from the worker (e.g. progress notifications).
The worker itself would need to send you progress notifications via
postMessage
function of course, e.g.: