I am using C# and WPF and am trying to slide an image strip along the screen. I am being honest, I got the code from some code sample on the Internet and took the parts I needed from it.
public double ImageOffset
{
get
{
try
{
return (double)this.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Background,
(DispatcherOperationCallback)delegate
{ return GetValue(ImageOffsetProperty); }, ImageOffsetProperty);
}
catch
{
return (double)this.GetValue(ImageOffsetProperty);
}
}
set
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
(SendOrPostCallback)delegate
{ SetValue(ImageOffsetProperty, (object)value); },
(object)value);
}
}
Sometimes when the program tries to get the ImageOffsetProperty an InvalidOperationException: Cannot perform this operation while dispatcher processing is suspended
happens and I have no idea how to fix it.
I also tried Dispatcher.BeginInvoke
, safe the ImageOffsetProperty in a Double and then return it, but it always returned 0.
What is causing the InvalidOperationException
?