c# - InvalidOperationException - object is currently in use elsewhere -


I have gone but did not help with this.

The case is different here. I'm using backgroundworkers The first page user starts working on the user's image input and I'm calling 3 other backgroundwalkers in the first BackwardWorkWorkerReinerary ()

  algo1backgroundworker.RunWorkerAsync ( ); Algo2backgroundworker.RunWorkerAsync (); Algo3backgroundworker.RunWorkerAsync ();  

This is the code for each:

  algo1backgroundworker_DoWork () {Image img = this.picturebox.Image; Imgclone = img.clone (); // work on imgclone and output it) algo2backgroundworker_DoWork () {image img = this.picturebox.Image; Imgclone = img.clone (); / / Work on Imgclone and output it}  

Similar works are done in other algorithms * Backgragrunderworker_workwork.

Now I am getting some time "InvalidOperationException - object is nowhere in use" Its very arbitrary I have some time in it algo1backgroundworker_DoWork and sometimes in algo2backgroundworker_DoWork and sometimes in the application. Run (new myWindowsForm ());

I have no clue about what is happening, there is a lock inside the GDI + which prevents two threads from reaching a bitmap at the same time.

This is not a locked type lock, it's a "programmer has done something wrong, I'm an exception Throwing "Like Lock, your threads are bombering because you are cloning the image in all threads (== to reach a bitmap). Your UI thread is bomber, because it is trying to get a bitmap (reach == a bitmap) on cloning the thread at the same time.

You will need to restrict access to only one bitmap thread. Before you launch BGW, clone images in the UI thread, each BGW needs its own copy of the image. Update PB's image property in RunWorkerCompleted event You will lose some concurrency in this way, but it is indispensable.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -