Saturday, July 6, 2019

c# - "System.InvalidOperationException: The object is currently in use elsewhere" - how do I resolve this?



I got this error when trying to update an image.
It was a cross-thread update, but I used .Invoke(), so that shouldn't be the problem, should it.


Answer



(Answering my own question, for others, and for future reference)




I think (not yet entirely sure) that this is because InvokeRequired will always return false if the control has not yet been loaded/shown. I have done a workaround which seems to work for the moment, which is to simple reference the handle of the associated control in its creator, like so:



var x = this.Handle; 


(See http://ikriv.com:8765/en/prog/info/dotnet/MysteriousHang.html - down? cached version)



(Related question: Boiler plate code replacement - is there anything bad about this code?)


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...