fix: simplified add/remove of socket listener through usage of "Once"

This commit is contained in:
Denny09310
2025-11-10 10:40:51 +01:00
parent d8062aae00
commit adc1e81743
23 changed files with 310 additions and 750 deletions

View File

@@ -30,20 +30,15 @@ namespace ElectronNET.API
{
get
{
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
var tcs = new TaskCompletionSource<Rectangle>();
Task.Run(() =>
{
BridgeConnector.Socket.On<Rectangle>("browserView-getBounds-reply", (result) =>
{
BridgeConnector.Socket.Off("browserView-getBounds-reply");
taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Once<Rectangle>("browserView-getBounds-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
});
return taskCompletionSource.Task.GetAwaiter().GetResult();
return tcs.Task.GetAwaiter().GetResult();
}
set
{