diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 810cdc34..fa94e2cc 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -81,6 +81,15 @@ private void FormBrowser_WindowStateChanged(object sender, EventArgs e){ // callback handlers + public void InvokeSafe(Action func){ + if (InvokeRequired){ + Invoke(func); + } + else{ + func(); + } + } + public void OpenSettings(){ // TODO } diff --git a/Core/Handling/ContextMenuHandler.cs b/Core/Handling/ContextMenuHandler.cs index 01e3fc4e..41c33d78 100644 --- a/Core/Handling/ContextMenuHandler.cs +++ b/Core/Handling/ContextMenuHandler.cs @@ -1,4 +1,5 @@ using CefSharp; +using System; namespace TweetDick.Core.Handling{ class ContextMenuHandler : IContextMenuHandler{ @@ -31,11 +32,17 @@ public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IF public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags){ switch((int)commandId){ case MenuSettings: - form.OpenSettings(); + form.InvokeSafe(() => { + form.OpenSettings(); + }); + return true; case MenuAbout: - form.OpenAbout(); + form.InvokeSafe(() => { + form.OpenAbout(); + }); + return true; } diff --git a/Core/Handling/TweetDeckBridge.cs b/Core/Handling/TweetDeckBridge.cs index 63303092..f68e0c5d 100644 --- a/Core/Handling/TweetDeckBridge.cs +++ b/Core/Handling/TweetDeckBridge.cs @@ -7,7 +7,9 @@ public TweetDeckBridge(FormBrowser form){ } public void OpenSettingsMenu(){ - form.OpenSettings(); + form.InvokeSafe(() => { + form.OpenSettings(); + }); } public void Log(string data){