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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -