{"record":{"id":"b5679d1d1d0ddbc7","repo":"dotnet/wpf","slug":"sr-verifyaccess","errorCode":null,"errorMessage":"SR.VerifyAccess","messagePattern":"SR\\.VerifyAccess","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs","lineNumber":216,"sourceCode":"        /// <summary>\n        ///     Verifies that the calling thread has access to this object.\n        /// </summary>\n        /// <remarks>\n        ///     Only the dispatcher thread may access DispatcherObjects.\n        ///     <p/>\n        ///     This method is public so that derived classes can probe to\n        ///     see if the calling thread has access to itself.\n        /// </remarks>\n        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]\n        public void VerifyAccess()\n        {\n            if(!CheckAccess())\n            {\n                // Used to inline VerifyAccess.\n                [DoesNotReturn]\n                [MethodImpl(MethodImplOptions.NoInlining)]\n                static void ThrowVerifyAccess()\n                    => throw new InvalidOperationException(SR.VerifyAccess);\n\n                ThrowVerifyAccess();\n            }\n        }\n\n        /// <summary>\n        ///     Begins the process of shutting down the dispatcher.\n        /// </summary>\n        /// <remarks>\n        ///     This API demand unrestricted UI Permission\n        /// </remarks>\n        public void BeginInvokeShutdown(DispatcherPriority priority) // NOTE: should be Priority\n        {\n\n            BeginInvoke(priority, new ShutdownCallback(ShutdownCallbackInternal));\n        }\n\n        /// <summary>","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs#L198-L234","documentation":"Dispatcher.VerifyAccess throws InvalidOperationException when the calling thread does not own (have access to) the Dispatcher — i.e. the call is not executing on the Dispatcher's thread. WPF UI objects and DispatcherObject-derived types require thread affinity; this is the enforced check.","triggerScenarios":"Touching UI elements or DispatcherObject members from a background/worker thread, Task.Run, async continuation on the thread pool, or an event/callback raised on a non-UI thread.","commonSituations":"Updating a control's property from a network/database callback; raising PropertyChanged from a worker thread for a property bound with non-marshaling binding; timer callbacks (System.Timers.Timer) touching UI; unit tests calling dispatcher-bound APIs off-thread.","solutions":["Marshal to the UI thread: dispatcher.Invoke/InvokeAsync(() => { ... }) before touching the object","Use Dispatcher.CheckAccess() to branch: run inline when on-thread, dispatch otherwise","Prefer async/await with a captured UI SynchronizationContext (await inside the handler) instead of manual threads","For cross-thread data updates, enable marshaling via Binding with automatic UI-thread sync where applicable"],"exampleFix":"// before\n// worker thread:\nstatusText.Text = \"Done\"; // InvalidOperationException: VerifyAccess\n// after\nDispatcher.InvokeAsync(() => statusText.Text = \"Done\");","handlingStrategy":"try-catch","validationCode":"if (!dispatcher.CheckAccess()) { dispatcher.InvokeAsync(action); return; }\naction();","typeGuard":"bool IsOnUiThread(DispatcherObject o) => o.Dispatcher.CheckAccess();","tryCatchPattern":"try { uiElement.Update(); } catch (InvalidOperationException) { App.Current.Dispatcher.InvokeAsync(() => uiElement.Update()); }","preventionTips":["Check Dispatcher.CheckAccess() before touching DispatcherObject members from shared code","Marshal via InvokeAsync/Invoke for all background-thread updates","Use async/await so continuations resume on the UI context","Prefer DispatcherTimer over System.Timers.Timer for UI updates"],"tags":["wpf","dispatcher","thread-affinity","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}