Reputation: 73
Hi I'm requesting two results from the main process but when I click the button, the app keeps freezing. Even devtools is not working .
ipcMain.on('fmail', (event, arg) => {
var fmaile = even
var fmaila = arg
ipcMain.on('fpass', (event, arg) => {
var fpasse = event
var fpassa = arg
console.log(fpassa)
console.log(fmaila)
fmaile.returnValue = "info"
fpasse.returnValue = "info"
})
})
var datamail = ipcRenderer.sendSync('fmail', "fmail");
var datapass = ipcRenderer.sendSync('fpass', "fpass");
console.log(datamail)
console.log(datapass)
Thanks for help.
Upvotes: 6
Views: 5436
Reputation: 5531
The docs is pretty clear on this one:
Sending a synchronous message will block the whole renderer process until the reply is received.
Since you don't provide a return value in your fmail
callback, no wonder it blocks your app.
Also, I guess you wanted to register both listeners individually. What you currently have is "add listener to 'fpass' every time 'fmail' is called back"
Your code should probably look like this (but cannot tell exactly really)
ipcMain.on('fmail', (event, arg) => {
console.log(arg)
event.returnValue = "info"
})
ipcMain.on('fpass', (event, arg) => {
console.log(arg)
event.returnValue = "info"
})
console.log(
ipcRenderer.sendSync('fmail', "fmail"),
ipcRenderer.sendSync('fpass', "fpass")
)
Docs also mentions a more convenient alternative for such cases: Use invoke()
Upvotes: 10