InvalidOperationException: Objects is currently used elsewhere! [closed]
I get that mistake.. I use a loop to run through a bunch of images to be drawn..I also use multithreading..
What could cause that problem and how could it be prevented?
I use winforms
Additional information:
it tells me if i use graphics after GetHDv method, call the ReleaseHDC method..
What does it mean?
section of the code:
A thread created like this:
Before I did this: BackgroundWorker1.RunWorkerAsync();
Now I am testing with this:
Backgroundworker back=new backgroundworker(); back.runworkerAsync();
is that the root of the 开发者_JAVA百科exception?
According to this page
What's really happening with "Object is currently in use elsewhere" is that GDI+ is complaining that the device context (DC) that it is trying to use is already "in use". With WinForms, this generally means there is a recursive Graphics.GetHdc occurring. GetHdc must match a ReleaseHdc before any other GetHdc.
And
You can encounter this exception if you're drawing to a form from multiple threads. You'll likely also be encountering a cross-threading exception as well. The solution in this case is to not use multiple threads when accessing a form, including drawing.
精彩评论