WPF, WinForms, and OffScreen in a single application #4271
-
I'm currently working on an application which hosts both WPF and Windows Forms controls (all within a C++ CLI monolith). There are also several service classes which utilize the OffScreen browser for capturing data/screenshots. I understand this is a terrible idea, but it's the reality of my situation for the time being. It seems to function. What are the implication of hosting each type of these controls in the same process? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I have a similar situation. I have a monolithic C# desktop application which hosts Windows Forms controls and also uses service classes (running in background threads) that use the OffScreen browser for capturing screenshots. The things to watch out for are around the initialization and shutdown of CEF, and also the construction and disposal of browser instances and any objects (resource handlers, etc.). If you don't get these right, when the application is exiting you may either hit an unmanaged exception in This is a good guide on doing initialize/shutdown correctly. https://github.com/cefsharp/CefSharp/wiki/General-Usage#initialize-and-shutdown In regards to individual browser instances, you should just ensure they are constructed and disposed on the same thread. This is probably only a concern for your service classes, since the WPF/WinForms browser should only ever be constructed/disposed automatically on the main UI thread. |
Beta Was this translation helpful? Give feedback.
I have a similar situation. I have a monolithic C# desktop application which hosts Windows Forms controls and also uses service classes (running in background threads) that use the OffScreen browser for capturing screenshots.
The things to watch out for are around the initialization and shutdown of CEF, and also the construction and disposal of browser instances and any objects (resource handlers, etc.). If you don't get these right, when the application is exiting you may either hit an unmanaged exception in
Cef.Shutdown()
, if it detects you have not disposed all objects, or a deadlock in the worst case scenario.This is a good guide on doing initialize/shutdown correctly. https://github…