electronsingle-threaded

Does Electron's main thread block BrowserWindow?


I'm building an application that runs an Electron application. What I'm seeing is that when the main thread gets busy running its own operations, BrowserWindow's thread will get blocked (just like it does if the BrowserWindow itself is running javascript).

Are these sharing the same thread? If so, what is the best way to separate them?


Solution

  • First of all, it's not really Electron's main thread. It'd be more accurate to say that it's Node's thread.

    Second, the Main process' main thread is used (among other things of course) to communicate between the Main process and the Renderer process that's used by the BrowserWindow, so if your main thread is performing a large synchronous operation, your main thread will block, and that could certainly affect the responsiveness of your window.

    what is the best way to separate them?

    I can't really provide a general solution that will be useful in all cases. You should present a specific example. What is your main thread busy doing?

    You can look into using WebWorkers. See here.