简体   繁体   English

电子ipcRenderer与ipcMain同步

[英]electron ipcRenderer sync with ipcMain

My problem is when i call ipcMain operation from the renderer process the renderer thread is stuck untill the ipcMain operation is done(sync instead async) 我的问题是当我从渲染器进程调用ipcMain操作时,渲染器线程被卡住,直到ipcMain操作完成(同步而不是异步)

Code example : 代码示例

Renderer.js Renderer.js

export const startCopy = data => {

  // Copy files tree to the drive
  ipcRenderer.send('copy-files', data);

  return new Promise((resolve, reject) => {

    ipcRenderer.on('copy-files-finished', (event, error) => {

      resolve(error);
    });
  });

}

Main.js Main.js

ipcMain.on('copy-files', (event, data) => {

  const error = copyFiles();

  console.log(error);

  event.sender.send('copy-files-finished', error);
});

Thanks ahead. 谢谢你

Yes same problem I encountered when I was working on electron problem, So I would like to suggest you one options that I think It is best one from my knowledge 是的,我在研究电子问题时遇到了同样的问题,所以我想向您建议一个我认为是最好的选择

Do time consuming task or system related task in separate window which is independent from Main window(Render process) It will never affect your Main window(Render process). 在独立于主窗口(渲染过程)的单独窗口中执行耗时的任务或与系统相关的任务,它将永远不会影响您的主窗口(渲染过程)。

after that send Message to Main window(Render process) in order to Notify and update UI. 之后,将消息发送到主窗口(渲染过程)以通知和更新UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM