“System.InvalidOperationException:该对象当前正在其他地方使用” - 我该如何解决? [英] "System.InvalidOperationException: The object is currently in use elsewhere" - how do I resolve this?

查看:3163
本文介绍了“System.InvalidOperationException:该对象当前正在其他地方使用” - 我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试更新图像时出现此错误。
这是一个跨线程更新,但是我使用了.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆