{"record":{"id":"6d53cde64b8d002f","repo":"cefsharp/CefSharp","slug":"can-only-be-used-when-cef-is-integrated-into-your","errorCode":null,"errorMessage":"Can only be used when CEF is integrated into your WPF Message Loop (MultiThreadedMessageLoop = false).","messagePattern":"Can only be used when CEF is integrated into your WPF Message Loop \\(MultiThreadedMessageLoop = false\\)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"CefSharp.Wpf/Rendering/DirectWritableBitmapRenderHandler.cs","lineNumber":37,"sourceCode":"    /// <seealso cref=\"CefSharp.Wpf.IRenderHandler\" />\n    public class DirectWritableBitmapRenderHandler : IRenderHandler\n    {\n        private readonly double dpiX;\n        private readonly double dpiY;\n        private readonly bool invalidateDirtyRect;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"WritableBitmapRenderHandler\"/> class.\n        /// </summary>\n        /// <param name=\"dpiX\">The dpi x.</param>\n        /// <param name=\"dpiY\">The dpi y.</param>\n        /// <param name=\"invalidateDirtyRect\">if true then only the direct rectangle will be updated, otherwise the whole bitmap will be redrawn</param>\n        /// <param name=\"dispatcherPriority\">priority at which the bitmap will be updated on the UI thread</param>\n        public DirectWritableBitmapRenderHandler(double dpiX, double dpiY, bool invalidateDirtyRect = true, DispatcherPriority dispatcherPriority = DispatcherPriority.Render)\n        {\n            if (!Cef.CurrentlyOnThread(CefThreadIds.TID_UI))\n            {\n                throw new NotSupportedException(\"Can only be used when CEF is integrated into your WPF Message Loop (MultiThreadedMessageLoop = false).\");\n            }\n\n            this.dpiX = dpiX;\n            this.dpiY = dpiY;\n            this.invalidateDirtyRect = invalidateDirtyRect;\n        }\n\n        /// <inheritdoc/>\n        void IDisposable.Dispose()\n        {\n\n        }\n\n        /// <inheritdoc/>\n        void IRenderHandler.OnAcceleratedPaint(bool isPopup, Rect dirtyRect, AcceleratedPaintInfo acceleratedPaintInfo)\n        {\n            throw new NotImplementedException();\n        }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Wpf/Rendering/DirectWritableBitmapRenderHandler.cs#L19-L55","documentation":"DirectWritableBitmapRenderHandler renders CEF output to a WPF WriteableBitmap by hooking into CEF's on-screen rendering callbacks on the UI thread. This only works when CEF is configured with MultiThreadedMessageLoop = false (integrated message loop), because in multi-threaded mode the CEF UI thread is a separate thread and the render callbacks fire off-dispatcher.","triggerScenarios":"Constructing DirectWritableBitmapRenderHandler while Cef.CurrentlyOnThread(CefThreadIds.TID_UI) returns false — i.e., CEF is running in the default multi-threaded message loop mode, or the constructor is called from a non-UI thread before CEF is initialized in integrated mode.","commonSituations":"Forgetting to set CefSettings.MultiThreadedMessageLoop = false and CefExternalMessagePump = false before Cef.Initialize. Creating the render handler before CEF has been initialized so the thread check has no valid context.","solutions":["Set CefSettings.MultiThreadedMessageLoop = false and CefExternalMessagePump = false in your CefSettings before Cef.Initialize.","Use an IntegratedMessageLoopBrowserProcessHandler to drive the message loop from the WPF Dispatcher.","Construct the render handler after CEF is initialized in integrated mode, on the UI thread."],"exampleFix":"// before — default multi-threaded mode, constructor throws\nvar settings = new CefSettings();\nCef.Initialize(settings);\nvar renderHandler = new DirectWritableBitmapRenderHandler(96, 96);\n\n// after — integrated message loop mode\nvar settings = new CefSettings\n{\n    MultiThreadedMessageLoop = false,\n    ExternalMessagePump = false\n};\nsettings.BrowserProcessHandler = new IntegratedMessageLoopBrowserProcessHandler(Dispatcher.CurrentDispatcher);\nCef.Initialize(settings);\nvar renderHandler = new DirectWritableBitmapRenderHandler(96, 96);","handlingStrategy":"validation","validationCode":"// Verify CEF is in integrated mode before constructing the handler\nif (!Cef.CurrentlyOnThread(CefThreadIds.TID_UI))\n{\n    throw new InvalidOperationException(\n        \"DirectWritableBitmapRenderHandler requires MultiThreadedMessageLoop=false. \" +\n        \"Set it in CefSettings before Cef.Initialize.\");\n}\nvar renderHandler = new DirectWritableBitmapRenderHandler(dpiX, dpiY);","typeGuard":null,"tryCatchPattern":"try\n{\n    var renderHandler = new DirectWritableBitmapRenderHandler(dpiX, dpiY);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"MultiThreadedMessageLoop\"))\n{\n    throw new InvalidOperationException(\n        \"Switch to integrated message loop (MultiThreadedMessageLoop=false) to use this render handler.\", ex);\n}","preventionTips":["Set CefSettings.MultiThreadedMessageLoop = false and ExternalMessagePump = false before Cef.Initialize when using this handler.","Provide an IntegratedMessageLoopBrowserProcessHandler in settings.BrowserProcessHandler.","Construct render handlers after CEF init on the UI thread."],"tags":["rendering","message-loop","configuration","wpf"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}