进度表和 XPCOM

发布于 2024-11-08 02:08:43 字数 444 浏览 1 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2024-11-15 02:08:43

你不应该直接从 JavaScript 创建新线程 - 这有很多线程安全问题,据我所知,这个功能在 Firefox 4 中不再可用。替代者是 chrome 工作人员: https://developer.mozilla.org/en/DOM/ChromeWorker。因此,您将像这样创建您的工作人员:

var worker = new ChromeWorker("script.js");
worker.postMessage(obj);

您还希望从工作人员接收消息(例如进度通知)。

worker.onmessage = function(event)
{
    if (event.data.type == "progress")
         alert("Worker progress: " + event.data.value);
    else if (event.data.type == "done")
         alert("Worker done!");
}

当然,工作人员本身需要通过 postMessage 函数向您发送进度通知,例如:

postMessage({type: "progress", value: done/total*100});

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:

var worker = new ChromeWorker("script.js");
worker.postMessage(obj);

You would also want to receive messages from the worker (e.g. progress notifications).

worker.onmessage = function(event)
{
    if (event.data.type == "progress")
         alert("Worker progress: " + event.data.value);
    else if (event.data.type == "done")
         alert("Worker done!");
}

The worker itself would need to send you progress notifications via postMessage function of course, e.g.:

postMessage({type: "progress", value: done/total*100});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文