cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.83k stars 2.92k forks source link

System.Application.Current in a WinForms solution #421

Closed msc-bsw closed 10 years ago

msc-bsw commented 10 years ago

Hey,

i implemented the WPF chromium web browser in my document viewer project, that is also WPF. This document viewer is embedded in a WinForms project, which is pretty big right now.

The WPF chromium web browser doesn't work in a WinForms project because "System.Application.Current" is null and therefore an exception comes up in RaiseCanExecuteChanged in CefSharp.Wpf.DelegateCommand.cs on line 38.

I know I could embed the CefSharp.WinForms WebBrowser to my WPF project but is it possible to make this work for my project setup?

Regards

msc

amaitland commented 10 years ago

Looking at the code the Dispatcher.CheckAccess() check isn't require anymore as it's always executed on the UI Thread.

If you remove that block from https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf/DelegateCommand.cs#L38 does it solve your problem?

msc-bsw commented 10 years ago

Yes, it does. But I don't know what side effects are coming with this removal.

Application.Current.Dispatcher.BeginInvoke((Action) RaiseCanExecuteChanged);
amaitland commented 10 years ago

RaiseCanExecuteChanged is only referenced three times, and that call is wrapped up by a method RaiseCommandsCanExecuteChanged which it's self is called here https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf/ChromiumWebBrowser.cs#L664 which you'll see is executed on the UI Thread.

So it's safe to remove :smile: The WPF version has had some progressive cleanup over the last few months, so there are still a few more improvements to make, as is always the case!

msc-bsw commented 10 years ago

Ok, thanks ;-)