c# - WritableBitmap does not work on separate Thread? -
I have a writeablebitmap that updates on a separate thread, especially in response to an event.
myWritableBitmap.Lock (); CopyMemory (myWritableBitmap.BackBuffer, ...); MyWritableBitmap.AddDirtyRect (...); MyWritableBitmap.Unlock (); When running on a different thread, then lock () command removes a system. Unknown Operation Exception .
If I run the same code like this:
this.Dispatcher.Invoke (new VoidDelegate (rep {// code like above ...}) ; No exception is thrown and the code runs completely. Is not lock-in purpose multi-threaded access permission? Why any thoughts are happening?
Many of the WPF drawing tasks should run in STAThread. The second piece of code runs your drawing function in the main UI thread.
EDIT: A bit more about threading in WPF.
Comments
Post a Comment