IPC, Inter-Process Communication, I's said that some technologies or methods for transmitting information or signals between at least two processes or threads. The above description comes from WIKI, which means that the method of transmitting information between Main Process and BrowserWindow is IPC.
What is IPC?
Inter-Process Communication (IPC) refers to some technologies or methods for transmitting information or signals between at least two processes or threads.
The above description comes from WIKI, which means that the method of transmitting information between Main Process and BrowserWindow is IPC.
How does IPC work in Electron?
Electron provides IpcRenderer and IpcMain to facilitate engineers to perform IPC
- Screen side (BrowserWindow) uses IpcRenderer
- The main process side (Main Process) uses IpcMain
How to write the code in practice ?
Shown below are 3 modes of communication
- Someone else will pick you up
IpcMain.on monitors messages from IpcRenderer.send
Then use event.reply
to return
For example: after you bring the kitten home, you ask the mother to help take care of your kitten and let her help feed it.
![](https://picx.zhimg.com/v2-a234ef76d5c002bb4601dc9113198aaf_720w.jpg?source=d16d100b)
- Wait for response You have been staring at the kitten because you are afraid that she will be hungry, but you have not done anything in the meantime.
![](https://picx.zhimg.com/v2-f9a1f74240929244763eb48a109a54e5_720w.jpg?source=d16d100b)
- Notification response When you clean the house, The cub cat is hungry and will "meow"
![](https://picx.zhimg.com/v2-fc0a4a0cf5b918aa365e57f9e3e123fc_720w.jpg?source=d16d100b)
The above three methods all start from the renderer process side. What should I do if I want to trigger the message from the main process?
![](https://pic1.zhimg.com/v2-d3cddd53f2c3f55b20d574fa0734e922_720w.jpg?source=d16d100b)