diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index 1293e00..e381510 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -296,7 +296,13 @@ namespace ElectronNET.API { if (_app == null) { - _app = new App(); + lock (_syncRoot) + { + if(_app == null) + { + _app = new App(); + } + } } return _app; @@ -304,6 +310,7 @@ namespace ElectronNET.API } private static App _app; + private static object _syncRoot = new Object(); private JsonSerializer _jsonSerializer = new JsonSerializer() { diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index e479e05..df10adb 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -6,6 +6,7 @@ namespace ElectronNET.API internal static class BridgeConnector { private static Socket _socket; + private static object _syncRoot = new Object(); public static Socket Socket { @@ -13,15 +14,27 @@ namespace ElectronNET.API { if(_socket == null && HybridSupport.IsElectronActive) { - _socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort); - _socket.On(Socket.EVENT_CONNECT, () => + lock (_syncRoot) { - Console.WriteLine("BridgeConnector connected!"); - }); + if (_socket == null && HybridSupport.IsElectronActive) + { + _socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort); + _socket.On(Socket.EVENT_CONNECT, () => + { + Console.WriteLine("BridgeConnector connected!"); + }); + } + } } else if(_socket == null && !HybridSupport.IsElectronActive) { - _socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false }); + lock (_syncRoot) + { + if (_socket == null && !HybridSupport.IsElectronActive) + { + _socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false }); + } + } } return _socket; diff --git a/ElectronNET.API/Clipboard.cs b/ElectronNET.API/Clipboard.cs index 06f05fc..340c0f5 100644 --- a/ElectronNET.API/Clipboard.cs +++ b/ElectronNET.API/Clipboard.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; +using System; using System.Threading.Tasks; namespace ElectronNET.API @@ -12,6 +13,7 @@ namespace ElectronNET.API public sealed class Clipboard { private static Clipboard _clipboard; + private static object _syncRoot = new Object(); internal Clipboard() { } @@ -21,7 +23,13 @@ namespace ElectronNET.API { if (_clipboard == null) { - _clipboard = new Clipboard(); + lock (_syncRoot) + { + if (_clipboard == null) + { + _clipboard = new Clipboard(); + } + } } return _clipboard; diff --git a/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index 053837d..2bb206f 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -13,6 +13,7 @@ namespace ElectronNET.API public sealed class Dialog { private static Dialog _dialog; + private static object _syncRoot = new Object(); internal Dialog() { } @@ -22,7 +23,13 @@ namespace ElectronNET.API { if (_dialog == null) { - _dialog = new Dialog(); + lock (_syncRoot) + { + if(_dialog == null) + { + _dialog = new Dialog(); + } + } } return _dialog; diff --git a/ElectronNET.API/GlobalShortcut.cs b/ElectronNET.API/GlobalShortcut.cs index a17668e..dd669bd 100644 --- a/ElectronNET.API/GlobalShortcut.cs +++ b/ElectronNET.API/GlobalShortcut.cs @@ -10,6 +10,7 @@ namespace ElectronNET.API public sealed class GlobalShortcut { private static GlobalShortcut _globalShortcut; + private static object _syncRoot = new Object(); internal GlobalShortcut() { } @@ -19,7 +20,13 @@ namespace ElectronNET.API { if (_globalShortcut == null) { - _globalShortcut = new GlobalShortcut(); + lock (_syncRoot) + { + if (_globalShortcut == null) + { + _globalShortcut = new GlobalShortcut(); + } + } } return _globalShortcut; diff --git a/ElectronNET.API/IpcMain.cs b/ElectronNET.API/IpcMain.cs index ee8c2dd..fedc900 100644 --- a/ElectronNET.API/IpcMain.cs +++ b/ElectronNET.API/IpcMain.cs @@ -14,6 +14,7 @@ namespace ElectronNET.API public sealed class IpcMain { private static IpcMain _ipcMain; + private static object _syncRoot = new Object(); internal IpcMain() { } @@ -23,7 +24,13 @@ namespace ElectronNET.API { if(_ipcMain == null) { - _ipcMain = new IpcMain(); + lock (_syncRoot) + { + if(_ipcMain == null) + { + _ipcMain = new IpcMain(); + } + } } return _ipcMain; diff --git a/ElectronNET.API/Menu.cs b/ElectronNET.API/Menu.cs index bbd593c..dcae110 100644 --- a/ElectronNET.API/Menu.cs +++ b/ElectronNET.API/Menu.cs @@ -16,6 +16,7 @@ namespace ElectronNET.API public sealed class Menu { private static Menu _menu; + private static object _syncRoot = new Object(); internal Menu() { } @@ -25,7 +26,13 @@ namespace ElectronNET.API { if (_menu == null) { - _menu = new Menu(); + lock (_syncRoot) + { + if(_menu == null) + { + _menu = new Menu(); + } + } } return _menu; diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs index b8c5579..9f232b3 100644 --- a/ElectronNET.API/Notification.cs +++ b/ElectronNET.API/Notification.cs @@ -15,6 +15,7 @@ namespace ElectronNET.API public sealed class Notification { private static Notification _notification; + private static object _syncRoot = new Object(); internal Notification() { } @@ -24,7 +25,13 @@ namespace ElectronNET.API { if (_notification == null) { - _notification = new Notification(); + lock (_syncRoot) + { + if (_notification == null) + { + _notification = new Notification(); + } + } } return _notification; diff --git a/ElectronNET.API/Screen.cs b/ElectronNET.API/Screen.cs index 8924289..72d6a4b 100644 --- a/ElectronNET.API/Screen.cs +++ b/ElectronNET.API/Screen.cs @@ -105,6 +105,7 @@ namespace ElectronNET.API private event Action _onDisplayMetricsChanged; private static Screen _screen; + private static object _syncRoot = new Object(); internal Screen() { } @@ -114,7 +115,13 @@ namespace ElectronNET.API { if (_screen == null) { - _screen = new Screen(); + lock (_syncRoot) + { + if (_screen == null) + { + _screen = new Screen(); + } + } } return _screen; diff --git a/ElectronNET.API/Shell.cs b/ElectronNET.API/Shell.cs index 15406c3..ec555a8 100644 --- a/ElectronNET.API/Shell.cs +++ b/ElectronNET.API/Shell.cs @@ -14,6 +14,7 @@ namespace ElectronNET.API public sealed class Shell { private static Shell _shell; + private static object _syncRoot = new Object(); internal Shell() { } @@ -23,7 +24,13 @@ namespace ElectronNET.API { if (_shell == null) { - _shell = new Shell(); + lock (_syncRoot) + { + if (_shell == null) + { + _shell = new Shell(); + } + } } return _shell; diff --git a/ElectronNET.API/Tray.cs b/ElectronNET.API/Tray.cs index 85c1927..e1b5a8e 100644 --- a/ElectronNET.API/Tray.cs +++ b/ElectronNET.API/Tray.cs @@ -201,6 +201,7 @@ namespace ElectronNET.API // TODO: Implement macOS Events private static Tray _tray; + private static object _syncRoot = new Object(); internal Tray() { } @@ -210,7 +211,13 @@ namespace ElectronNET.API { if (_tray == null) { - _tray = new Tray(); + lock (_syncRoot) + { + if (_tray == null) + { + _tray = new Tray(); + } + } } return _tray; diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs index f6519d5..409e77c 100644 --- a/ElectronNET.API/WindowManager.cs +++ b/ElectronNET.API/WindowManager.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -14,6 +15,7 @@ namespace ElectronNET.API public sealed class WindowManager { private static WindowManager _windowManager; + private static object _syncRoot = new Object(); internal WindowManager() { } @@ -23,7 +25,13 @@ namespace ElectronNET.API { if (_windowManager == null) { - _windowManager = new WindowManager(); + lock (_syncRoot) + { + if (_windowManager == null) + { + _windowManager = new WindowManager(); + } + } } return _windowManager;