Categories
Code Life

Electron vs. The Native Windows Frameworks

Or, is Electron really necessary for your next app?

Electron is starting to be used in many different popular applications, such as VSCode and WhatsApp, simply because of its cross-platform feature. But is that the only advantage that Electron provides?

As we will see by the end of this article, it is not the only benefit. We will look at how simpler it is to write a Windows app in Electron vs. native frameworks such as C++/C# WindowsForms and WPF. Why just Windows? Because the vast majority of programs are written for it, so for many categories of programs (e.g. games) there is a standardized library stack that’s used.

Background (tray) apps that display modal dialogs

Electron is probably overkill for this category. Modal dialogs are simple to create using WindowsForms, and C# also makes minimizing windows and displaying their notification (tray) icon very simple. This can also be done in Electron, but with a little more work.

Apps with a custom theme

Because WindowsForms does not support making custom window themes, developers use the WPF framework when they want to create a custom theme for their C# app. This process could take a lot of time, depending on the complexity of the theme.

Of course, theme-designing in Electron also takes time, but it’s helped by the abundance of HTML UI components that can be installed and inserted directly from npm, the NodeJS package manager. Only some WPF UI controls are free to use, while the vast majority remain closed-source, internal, and private, away from the public eye. While most HTML UI components are open-source and easy to obtain from Github.

Apps with heavy API/web service integration

Messaging clients such as Discord, Telegram, and Slack fall into this category. On C#, networking is done using the System.Net namespace, or more usually, with the ASP.NET framework. In C++, more low-level socket functions are used, hence why complex networking is traditionally done in C#.

System.Net has classes to manage cookies, network credentials, requests and responses, and HTTP listeners, among others. When used correctly, formidable network-enabled C# programs can be developed.

A positive trait of C# networking classes is that the compiler will detect most of the incorrect usages of these classes, which can save you hours of runtime debugging. This is not the case for Node.js and Electron apps, where all code is evaluated at runtime, and could silently fail then.

Worse (for Electron), as the bundled code is usually minified, it is difficult to get a stack trace that corresponds to your source code.

That is not to say that Electron is not good for building network apps. On the contrary, libraries such as Axios and node-fetch take care of networking very well. Asynchronous requests are also (slightly) easier to perform on NodeJS due to the language architecture. Additionally, NestJS is often used to make entire back-end APIs.

Video games and other GPU-intense apps

While HTML5 games built using WebGL-emitting game engines such as Unity are starting to emerge, C#/C++ and WPF still dominate the video game industry, due to the heavy use of graphics frameworks such as DirectX and OpenGL. In particular, there is no easy way to integrate Electron and DirectX, because the latter is a Windows-specific technology.

CAD & designer programs, and other kinds of graphics-accelerated programs, make use of OpenGL instead of DirectX, and since Electron apps can use WebGL, the level of difficulty of developing these kinds of applications in both platforms is about the same.

Microsoft Store apps

Here is a surprise: You can publish Microsoft Store apps that are built with Electron. They will need at least Windows 10 1607 to run, and they will compile to AppX packages that you can publish on the Store after Microsoft manually verifies the application.


So in this area, it doesn’t look like there are advantages or drawbacks to using either language, because the end-product is the same - with the exception that C# can make UWP apps, but Electron can’t, but to be fair, most people are not running UWP apps on the alternate platforms such as Xbox anyway.


The conclusion of all this is that whether you choose to write your app in C# and WPF or in NodeJS and Electron depends on whether you plan to port it to browsers eventually, or whether you want to use GPU acceleration. C#/C++ is the clear winner for GPU-accelerated programs, while for deploying your desktop app to the web, Electron is the way to go.

Desktop app deployment to web browsers has some uses. For instance, if you make an open-source code editor using Electron, then services that let you run and test code online can embed your editor inside their service, for people to use on the web. This is actually how Stackblitz is embedding VScode and a Chromium browser window in its web IDE.

By Ali Sherief

Editor-in-chief and serial coder & blogger.