Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NWJS,Electron-DOM在长时间运行过程中未更新_Electron_Nwjs - Fatal编程技术网

NWJS,Electron-DOM在长时间运行过程中未更新

NWJS,Electron-DOM在长时间运行过程中未更新,electron,nwjs,Electron,Nwjs,就像在中一样,我有一个长期运行的过程,在这个过程中,我希望更新应用程序唯一窗口的HTML——但DOM直到上述过程完成后才得到更新 NW和Electron都是这种情况 正在调用代码,因为同一例程也会登录到控制台——该控制台通过传递给流程的窗口实例进行访问,流程位于节点模块中 我找不到任何引用此类问题的文档,也找不到可能有帮助的Chromium标志 当使用setInterval以每秒的时间填充元素的innerText时,更新会在长时间运行的文件解析过程中停止 编辑:这个问题是我在Google搜索“N

就像在中一样,我有一个长期运行的过程,在这个过程中,我希望更新应用程序唯一窗口的HTML——但DOM直到上述过程完成后才得到更新

NW和Electron都是这种情况

正在调用代码,因为同一例程也会登录到
控制台
——该控制台通过传递给流程的
窗口
实例进行访问,流程位于节点模块中

我找不到任何引用此类问题的文档,也找不到可能有帮助的Chromium标志

当使用
setInterval
以每秒的时间填充元素的
innerText
时,更新会在长时间运行的文件解析过程中停止


编辑:这个问题是我在Google搜索“NWJS不更新DOM”时的第一个结果。…

长时间运行的进程会阻止Chromium主进程,也会阻止渲染器

解决方案是创建一个单独的进程,并让它通过IPC将状态更新发送回渲染器:

        this._service = fork(
            path.join(__dirname, 'service'),
            [],
            { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] }
        );

        this._service.on('error', (err) => {
            console.log('child error', err);
        });

        this._service.on('message', msg => {
            console.log('message from child:', msg);
            switch (msg.cmd) {
                case 'hello':
                    console.log('hello from parent');
                    break;
                case 'log':
                    this.parentLog(msg.html);
                    break;
                case 'progress':
                    this.progressBar.update(msg.pc);
                    break;
            }
        });
在生成的子流程中(上例中名为
service.js
),使用
process.send
将JSON传输到父流程:

const childLog = (html) => {
    process.send({ cmd: 'log', html: html });
}

请注意,如果父级不是Electron渲染器,则它可能通过从渲染器传递的
窗口访问DOM。

阻止Chromium主进程的长时间运行进程也会阻止渲染器

解决方案是创建一个单独的进程,并让它通过IPC将状态更新发送回渲染器:

        this._service = fork(
            path.join(__dirname, 'service'),
            [],
            { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] }
        );

        this._service.on('error', (err) => {
            console.log('child error', err);
        });

        this._service.on('message', msg => {
            console.log('message from child:', msg);
            switch (msg.cmd) {
                case 'hello':
                    console.log('hello from parent');
                    break;
                case 'log':
                    this.parentLog(msg.html);
                    break;
                case 'progress':
                    this.progressBar.update(msg.pc);
                    break;
            }
        });
在生成的子流程中(上例中名为
service.js
),使用
process.send
将JSON传输到父流程:

const childLog = (html) => {
    process.send({ cmd: 'log', html: html });
}
请注意,如果父级不是Electron渲染器,则它可能通过从渲染器传递的
窗口访问DOM