Working on building a Tabbed Webbrowser using CEF. It works properly until trying to create a new Window(new Form) from the a class that implements ILifeSpanHandler to catch new window events. It works when calling Form.Show() but fails when calling Form.ShowDialog() as this is being called from a different Thread. Is their a way to call ShowDialog() on new windows from another thread?
Here is how the call looks.
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
newBrowser = null;
PopupWindow popup = new PopupWindow()
{
Url = targetUrl
};
popup.Show();
}
After @graeme_grant help and google have come up with a solution to use show() to act as a ShowDialog(). Below is a working solution to the problem.
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
newBrowser = null;
Dispatcher.Execute(() =>
{
Form form = MainWindow.ActiveForm;
PopupWindow popupWindow = new PopupWindow()
{
Url = targetUrl,
Width = 1000,
Height = 1000,
};
popupWindow.Shown += delegate
{
form.Enabled = false;
};
popupWindow.FormClosed += delegate
{
form.Enabled = true;
};
popupWindow.Show();
});
What I have tried:
Tried calling form.ShowDialog() over Form.Show()