c# - Multithread: ThreadPool and show image exception -


I should show the order of the image in a new thread because otherwise the frame is lost for the complexity of the conection operation. I have tried to:

 using  (bodyfire bodyfrem = e.frame reference.acquirefreem ()) {if (bodyfram! = Empty) {if (this.bodies == Null) {this.bodies = new body [bodyfreight. Bodycount]; } // The first time called getandrefreshbodydata, Kinect will allocate in each body array. // Until those objects are not resolved and the null is not in the array, // those body objects will be reused. Bodyframe.GetAndRefreshBodyData (this.bodies); DataReceived = true; } And console. WrightLine (); } BodyCustom [] Entity custom = deserialize (directoryTxt [frameCount]); Sw.WriteLine ("frame" + framecount); If (data received) {sw.WriteLine (data received); ThreadPool.QueueUserWorkItem (showImage, frameCount); ..............  

and:

  Private zero show image (object framecount) {imageReference.Source = New bitmap image (new ury (@directoryjpg [(int framescount]])); }  

But I have an unmanaged exception of type 'System.InvalidOperationException' in the WindowsBase.dll file: Unable to access the object from the object Calling thread because the object is owned by another thread

I think the error object depends on the image because I use it somewhere else, but by commenting it also This error is detected. Why?

I am using the Image Class (System.Windows.Controls)

The problem is that you can not update UI on the background thread. (It also helps if you translate an error message in English, then I would say that most people do not understand Italian here.)

You have to do martial back to the UI thread to change the image.

You will first need to store the current synchronization context.

This is the easiest in the constructor.

  Public class MyObject {Personal synchronization tool edit timeContactContax; Public MyObject () {CurrentSynchronizationContext = System.Threading.SynchronizationContext.Current; }}  

Next, in your ThreadPool.QueueUserWorkItem operation (whether it is a representative or lambda), add something like this:

 < / Pre> 

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -