Comments (11)
Well, I wouldn't expect anything different. Why are you opening a window in a new thread? That's a pretty unusual thing to do... In any case, it's not a scenario I intend to support.
If you really need to do that, you can try to Freeze()
the image before you assign it to AnimatedSource
, but I can't guarantee it will work.
from wpfanimatedgif.
Using WpfAnimatedGif within devexpress control also fails with the message:
<DataTemplate x:Key="waitIndicator">
<dx:WaitIndicator DeferedVisibility="True">
<Image Height="61" Stretch="None" Source="pack://application:,,,/Loader-Blue.gif" />
</dx:WaitIndicator>
</DataTemplate>
<dxwui:NavigationFrame>
</dxmvvm:Interaction.Triggers>
<dxmvvm:Interaction.Behaviors>
<dxwuin:FrameNavigationService />
<dxwuin:FrameDocumentUIService ShowSplashScreen="True">
<dxwuin:FrameDocumentUIService.SplashScreenService>
<dx:DXSplashScreenService x:Name="WaitScreenService" ViewTemplate="{StaticResource waitIndicator}" SplashScreenStartupLocation="CenterOwner" />
</dxwuin:FrameDocumentUIService.SplashScreenService>
<dxwuin:FrameDocumentUIService.PageAdornerControlStyle>
<Style TargetType="dxwui:PageAdornerControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="dxwui:PageAdornerControl">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</dxwuin:FrameDocumentUIService.PageAdornerControlStyle>
</dxwuin:FrameDocumentUIService>
</dxmvvm:Interaction.Behaviors>
</dxwui:NavigationFrame>
09:11:45,402 e ap 032 UnhandledException: System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.Media.Imaging.BitmapDecoder.ToString()
at System.Windows.Media.Imaging.BitmapFrameDecode.ConvertToString(String format, IFormatProvider provider)
at System.Windows.Media.ImageSource.ToString()
at WpfAnimatedGif.AnimationCache.CacheKey.GetUri(ImageSource image)
at WpfAnimatedGif.AnimationCache.CacheKey.ImageEquals(ImageSource x, ImageSource y)
at WpfAnimatedGif.AnimationCache.CacheKey.Equals(CacheKey other)
at WpfAnimatedGif.AnimationCache.CacheKey.Equals(Object obj)
at System.Collections.Generic.ObjectEqualityComparer`1.Equals(T x, T y)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at WpfAnimatedGif.ImageBehavior.GetAnimation(Image imageControl, BitmapSource source)
at WpfAnimatedGif.ImageBehavior.InitAnimationOrImage(Image imageControl)
at WpfAnimatedGif.ImageBehavior.ImageControlLoaded(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
from wpfanimatedgif.
Not sure what DevExpress is doing here, but I suspect DXSplashScreenService
is showing a window on a separate thread. As I said, this is not a supported scenario, but you might be able to make it work by freezing the image before using it.
from wpfanimatedgif.
Closing due to inactivity
from wpfanimatedgif.
I too am affected by this. It seems not that unusual a thing to do - beyond the hobby project scope.
from wpfanimatedgif.
Hi @lsim,
It's not a problem with the library, it's due to how WPF works. If an DependencyObject
object is created on one thread, you can't manipulate it with another thread. There's nothing I can do about it.
Did you try what I suggested to @dusansmail and @igharrac? i.e. freezing the image? They never said if it worked for them.
from wpfanimatedgif.
That part of our code isn't my specific area of expertise - so I can't say yet how we might work around the issue. My main source of bafflement is that even when window and controls are all created on the same STA thread (not the Main thread), it still exhibits this behavior. I'll study it some more - I'm probably overlooking something.
I'll look into if and when we create a DependencyObject
- when I figure out what that is :)
.. and try to remember to report back here with my findings.
Thanks for a super speedy reply btw
from wpfanimatedgif.
It works fine outside the main thread so long as all our gif-showing windows are run on the same STA thread. My concern was that even this wouldn't be enough.
Despite our efforts to clean up after each such window is closed, something relating to the gif must remain, which gives rise to the thread related exception when the next window initializes. Until now, we have spun up a new STA thread for each such window.
I think we can probably make this work in our project.
from wpfanimatedgif.
@lsim this might be because animations are cached (so that if you have the same GIF images shown multiple times, the animation isn't reconstructed every time). Each animation is removed from the cache when the last instance of the GIF is cleared. Maybe try to clear the AnimatedSource
before closing the window?
from wpfanimatedgif.
Unfortunately, that experiment is probably out the scope of my current situation now that I have things working again. I would have to rewire the xaml bindings in a semi complicated setup.
If that cache is the root of the problem, maybe it could be a candidate for a ThreadLocal
kind of thing? You would then take a perf hit if you use multiple threads, but things would work.
from wpfanimatedgif.
maybe it could be a candidate for a
ThreadLocal
kind of thing?
If it's indeed the cause of the problem, yes, that would probably solve it.
from wpfanimatedgif.
Related Issues (20)
- Set from code HOT 2
- Huge memory consumption HOT 1
- Application freezes when resizing the window HOT 1
- Memory Leak HOT 3
- Version is 0.0.0.0 HOT 6
- Crash application when reading specific gif HOT 1
- error HOT 1
- Memory Release Problem (2) HOT 11
- When changing GIFs, the animation stops working HOT 11
- An XDG0062 error is thrown HOT 4
- Is there a way to free the BitmapImage ressources? HOT 2
- Some gif pics cannot display correctly. HOT 3
- Does not display a specific gif file HOT 3
- Not working with DrawingImage HOT 5
- File version lowered to 1.0.0 HOT 4
- Cache gif in memory so it plays instantly when shown HOT 7
- Delay animation for any gif? HOT 4
- Memory Leak HOT 3
- Pause and play with XAML HOT 1
- System.Windows.Markup.XamlParseException: Could not load 'file or assembly 'WpfAnimatedGif HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wpfanimatedgif.