{"record":{"id":"19f98e7c01893f18","repo":"dotnet/wpf","slug":"sr-media-notallowedwhiletimingengineincontrol","errorCode":null,"errorMessage":"SR.Media_NotAllowedWhileTimingEngineInControl","messagePattern":"SR\\.Media_NotAllowedWhileTimingEngineInControl","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaPlayerState.cs","lineNumber":999,"sourceCode":"            _dispatcher.VerifyAccess();\n\n            if (_nativeMedia == null || _nativeMedia.IsInvalid)\n            {\n                throw new System.NotSupportedException(SR.Image_BadVersion);\n            }\n        }\n\n        /// <summary>\n        /// Verifies that this player is not currently controlled by a clock. Some actions are\n        /// invalid while we are under clock control.\n        /// </summary>\n        private\n        void\n        VerifyNotControlledByClock()\n        {\n            if (Clock != null)\n            {\n                throw new InvalidOperationException(SR.Media_NotAllowedWhileTimingEngineInControl);\n            }\n        }\n\n        /// <summary>\n        /// SendMediaPlayerCommand\n        /// </summary>              SecurityNote\n        private\n        void\n        SendMediaPlayerCommand(\n            DUCE.Channel            channel,\n            DUCE.ResourceHandle     handle,\n            bool                    notifyUceDirectly\n            )\n        {\n            // This is an interrop call, but, it does not set a last error being a COM call. \n\n            //\n            // AddRef to ensure the media player stays alive during transport, even if the","sourceCodeStart":981,"sourceCodeEnd":1017,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaPlayerState.cs#L981-L1017","documentation":"MediaPlayerState.VerifyNotControlledByClock throws InvalidOperationException when the media player is being driven by a MediaClock/MediaTimeline (Clock != null). While the timing engine controls playback, direct commands like setting Position, SpeedRatio, or calling Open/Play/Pause/Stop are forbidden because the clock owns the timeline.","triggerScenarios":"Setting Position or SpeedRatio, or calling Open/Play/Pause/Stop, on a MediaPlayer/MediaElement whose Clock property is non-null - i.e. the player was created via MediaClock (e.g. MediaTimeline with BeginAnimation/Storyboard or Clock = timeline.CreateClock()).","commonSituations":"Mixing storyboard/clock-driven MediaElement playback with imperative Play/Pause calls in the same control; using MediaTimeline in a Storyboard then trying player.Position = new TimeSpan(...) in a slider handler.","solutions":["Use the clock's Controller (e.g. clock.Controller.Seek/SpeedRatio/Pause/Resume) instead of player methods when under clock control","Remove the Clock association (e.g. don't create the player from MediaTimeline) if you want imperative control","Check Clock != null before calling player APIs and branch to the clock-controller path"],"exampleFix":"// before\nplayer.Position = TimeSpan.FromSeconds(10); // InvalidOperationException when clock-controlled\n// after\nif (player.Clock != null)\n    player.Clock.Controller.Seek(TimeSpan.FromSeconds(10), TimeSeekOrigin.BeginTime);\nelse\n    player.Position = TimeSpan.FromSeconds(10);","handlingStrategy":"validation","validationCode":"if (player.Clock != null) { /* use clock.Controller for seek/speed/play-pause */ }","typeGuard":"bool IsClockControlled(MediaPlayer p) => p.Clock != null;","tryCatchPattern":"try { player.Position = pos; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Timing\") || ex.Message.Contains(\"clock\")) { player.Clock?.Controller?.Seek(pos, TimeSeekOrigin.BeginTime); }","preventionTips":["Never mix Storyboard/MediaTimeline control with imperative Play/Pause/Stop on the same player","Route all control through clock.Controller when Clock != null","Decide up front whether a player is clock-driven or imperative"],"tags":["wpf","media","animation","clock"],"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"}