I've got a WritableBitmap that updates on a separate thread, specifically in response to an event.
myWritableBitmap.Lock();
CopyMemory(myWritableBitmap.BackBuffer, ...);
myWritableBitmap.AddDirtyRect(...);
myWritableBitmap.Unlock();
When run on a separate thread as-is, the Lock()
command throws a System.InvalidOperationException
.
If I run the same code like this:
this.Dispatcher.Invoke(new VoidDelegate(delegate
{
//Same code as above...
}));
No exceptions are thrown and the code runs perfectly. Wouldn't the purpose of the Lock() be to allow multi-threaded access? Any idea why this is happening?