“System.InvalidOperationException:该对象当前正在其他地方使用” - 我该如何解决? [英] "System.InvalidOperationException: The object is currently in use elsewhere" - how do I resolve this?
问题描述
尝试更新图像时出现此错误。
这是一个跨线程更新,但是我使用了.Invoke(),所以不应该是问题,应该如何。
(回答我自己的问题,对于其他人,以备将来参考)
em>(还不完全确定),这是因为如果控件尚未加载/显示,InvokeRequired将始终返回false。我已经做了一个解决方案,似乎现在工作,这是简单地引用相关控件在其创建者的句柄,如下所示:
code> var x = this.Handle;
(见 http://ikriv.com:8765/en/prog/info/dotnet/MysteriousHang.html - down? $ b
(相关问题:锅炉代码替换 - 这个代码有什么不好吗?)
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.
(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?)
这篇关于“System.InvalidOperationException:该对象当前正在其他地方使用” - 我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!