Guidance on calling Electon APIs from Blazor server code #907

Closed
opened 2026-01-29 16:51:44 +00:00 by claunia · 1 comment
Owner

Originally created by @chrissmithptml on GitHub (Aug 1, 2023).

Maybe I'm just doing something wrong (which would not be the first time), but I just want to make sure.

So I have a Blazor Server app running in Electron.NET. All Blazor stuff is fine, as are all standard javascript calls.

If I wire up calls to the Electron.NET API behind the scenes (say setting up the electron menus in my Program.cs), this all works fine.

However, when I try to call Electon APIs via a Blazor button on the server, my app not only DOESN'T do the expected Electron action, but it ends up freezing my app.

My call is pretty simple, but maybe this is just not possible / there's something else I must do to make this work

public void SomeButtonHandler() {
     var somePath = "/some/path/on/the/workstation";
     Electron.Shell.ShowItemInFolderAsync(somePath).Wait();
} 

Should this work just fine? Is there something else I need to do / some other way I need to wire this up in a Blazor Server app? Just trying to get some confirmation.

App Details
Blazor app type: Blazor server
Electon.NET Version: latest
.NET Version: 6.0x

Originally created by @chrissmithptml on GitHub (Aug 1, 2023). Maybe I'm just doing something wrong (which would not be the first time), but I just want to make sure. So I have a Blazor Server app running in Electron.NET. All Blazor stuff is fine, as are all standard javascript calls. If I wire up calls to the Electron.NET API behind the scenes (say setting up the electron menus in my Program.cs), this all works fine. However, when I try to call Electon APIs via a Blazor button on the server, my app not only DOESN'T do the expected Electron action, but it ends up freezing my app. My call is pretty simple, but maybe this is just not possible / there's something else I must do to make this work ``` public void SomeButtonHandler() { var somePath = "/some/path/on/the/workstation"; Electron.Shell.ShowItemInFolderAsync(somePath).Wait(); } ``` Should this work just fine? Is there something else I need to do / some other way I need to wire this up in a Blazor Server app? Just trying to get some confirmation. **App Details** Blazor app type: Blazor server Electon.NET Version: latest .NET Version: 6.0x
claunia added the question label 2026-01-29 16:51:44 +00:00
Author
Owner

@chrissmithptml commented on GitHub (Aug 16, 2023):

Worked it out, in case anyone else bumps up against this kind of thing.

My button method was a void, and my call to Electron used a .Wait(). That and .Result appear to be big ol' no-nos. They do NOT work. You have to ensure the Electron Shell calls are full on await async calls or they won't work as expected.

public async Task SomeButtonHandler() {
     var somePath = "/some/path/on/the/workstation";
     await Electron.Shell.ShowItemInFolderAsync(somePath);
} 
@chrissmithptml commented on GitHub (Aug 16, 2023): Worked it out, in case anyone else bumps up against this kind of thing. My button method was a void, and my call to Electron used a `.Wait()`. That and `.Result` appear to be big ol' no-nos. They do NOT work. You have to ensure the Electron Shell calls are full on await async calls or they won't work as expected. ``` public async Task SomeButtonHandler() { var somePath = "/some/path/on/the/workstation"; await Electron.Shell.ShowItemInFolderAsync(somePath); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#907