question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is call of Dispatcher in SvgDrawingCanvas necessary?

See original GitHub issue

I can’t reproduce it in isolated small project, but in big WPF-application some svg-icons crashes in SvgDrawingCanvas.UnloadDiagrams() on Dispatcher.Invoke with “Cannot perform this operation while dispatcher processing is suspended.” exception in Main (UI) Thread. This trouble reproduces every time. I suppose it relates from call stack.

Crash

This is call stack of this crash:

>	SharpVectors.Runtime.Wpf.dll!SharpVectors.Runtime.SvgDrawingCanvas.UnloadDiagrams() Line 267	C#
 	SharpVectors.Converters.Wpf.dll!SharpVectors.Converters.SvgViewbox.OnUnloadDiagram() Line 1202	C#
 	SharpVectors.Converters.Wpf.dll!SharpVectors.Converters.SvgViewbox.OnLoadDrawing(System.Windows.Media.DrawingGroup drawing) Line 1183	C#
 	SharpVectors.Converters.Wpf.dll!SharpVectors.Converters.SvgViewbox.OnSettingsChanged() Line 950	C#
 	SharpVectors.Converters.Wpf.dll!SharpVectors.Converters.SvgViewbox.OnSourceChanged(System.Windows.DependencyObject obj, System.Windows.DependencyPropertyChangedEventArgs args) Line 1330	C#
 	WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)	Unknown
 	WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args)	Unknown
 	WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)	Unknown
 	PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplatedParentValue(System.Windows.DependencyObject container, MS.Internal.FrameworkObject child, int childIndex, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, System.Windows.DependencyProperty dp, System.Windows.FrameworkElementFactory templateRoot)	Unknown
 	PresentationFramework.dll!System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(System.Windows.DependencyObject container, MS.Internal.FrameworkObject child, int childIndex, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, bool isDetach, System.Windows.FrameworkElementFactory templateRoot)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(System.Windows.DependencyObject container, object currentObject)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.HandleBeforeProperties(object createdObject, ref System.Windows.DependencyObject rootObject, System.Windows.DependencyObject container, System.Windows.FrameworkElement feContainer, System.Windows.Markup.INameScope nameScope)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent.AnonymousMethod__2(object sender, System.Xaml.XamlObjectEventArgs args)	Unknown
 	System.Xaml.dll!System.Xaml.XamlObjectWriter.OnBeforeProperties(object value)	Unknown
 	System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(MS.Internal.Xaml.Context.ObjectWriterContext ctx)	Unknown
 	System.Xaml.dll!System.Xaml.XamlObjectWriter.WriteEndObject()	Unknown
 	System.Xaml.dll!System.Xaml.XamlWriter.WriteNode(System.Xaml.XamlReader reader)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlReader templateReader, System.Xaml.XamlObjectWriter currentWriter)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlObjectWriter objectWriter)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(System.Windows.DependencyObject container, System.Windows.Markup.IComponentConnector componentConnector, System.Windows.Markup.IStyleConnector styleConnector, System.Collections.Generic.List<System.Windows.DependencyObject> affectedChildren, System.Windows.UncommonField<System.Collections.Hashtable> templatedNonFeChildrenField)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadContent(System.Windows.DependencyObject container, System.Collections.Generic.List<System.Windows.DependencyObject> affectedChildren)	Unknown
 	PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> templateDataField, System.Windows.FrameworkElement container)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate()	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown
 	PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout()	Unknown
 	PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg)	Unknown
 	PresentationCore.dll!System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()	Unknown
 	PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()	Unknown
 	PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget)	Unknown
 	PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)	Unknown
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()	Unknown
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)	Unknown
 	WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()	Unknown
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()	Unknown
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown
 	WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown
 	WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)	Unknown
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)	Unknown
 	WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)	Unknown
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)	Unknown
 	PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)	Unknown
 	PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)	Unknown
 	PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)	Unknown
 	PresentationFramework.dll!System.Windows.Application.Run()	Unknown
 	Integral.RailwayEditor.Shell.exe!Integral.RailwayEditor.Shell.App.Main()	Unknown

Probably it occurs in cases like this: http://apaers.com/wpf-error-cannot-perform-operation-while-dispatcher-processing-is-suspended/

If I just remove this Invoke with empty action all works fine and I can’t find any troubles with svg rendering. 😃 Is this invoke necessary? For what it needs?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Kozinakacommented, Jul 9, 2019

I’ve checked it. No exceptions and visible troubles in both cases. All my icons displays correct: from SvgImage directly in XAML and from static binding to result of SvgImage.CreateDrawing() as ImageSource.

        public void UnloadDiagrams()
        {
            _offsetX = 0;
            _offsetY = 0;
            _bounds  = new Rect(0, 0, 1, 1);

            _wholeDrawing = null;

            _displayTransform = Transform.Identity;

            this.ClearVisuals();
            this.ClearDrawings();

            this.InvalidateMeasure();
            this.UpdateLayout();

            //this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, EmptyDelegate);
        }
1reaction
Kozinakacommented, Jul 5, 2019

Okay! I got it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

C#, WPF, Automatically call Dispatcher.Invoke when ...
Invoke call carries a fair amount of overhead, since it posts a message into the Dispatcher's message queue which must be processed. Consider ......
Read more >
Dispatcher.Invoke Method (System.Windows.Threading)
Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns. Invoke(DispatcherPriority, ...
Read more >
Releases · bluekvirus/Stage.js
triggerMethodInversed() to always call onE() before all the 'e' on()s;; Aligned 'view:navigate-to' ... Added SVG drawing (canvas creation, gradient filling, ...
Read more >
Using Zen Components - InterSystems Documentation
Call the executeQuery method of the %ZEN.Component.tablePane. This causes the data query to be re-executed and<br />.
Read more >
Freelance Jobs and Contests
Browse jobs and contests on Freelancer. Find programming, web development, design, writing, data entry jobs and many more. Page - 8.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found