WinForms-控件上的MultiThreading InvokeRequired有时会失败 [英] WinForms - MultiThreading InvokeRequired on Control fails sometimes

查看:84
本文介绍了WinForms-控件上的MultiThreading InvokeRequired有时会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



1)应用包含

MainForm:-这是应用程序的大型机.

BaseForm:-包含控件,例如列表框

ChildForm1:-从BaseForm派生,后者显示列表框

Worker_Thread:-调用并更新Main_Thread应用程序的ListBox项.

2)申请工作:-

在MainFrame构造函数中,创建并开始运行线程.

在MenuItem上,单击Mainform Application,
我创建(BaseForm childform = new childForm1)对象和childForm1.show();

使用Workerthread,我调用了主窗体的列表框控件,并将项目添加到列表框中,并显示了它.
当我关闭窗体并重新打开(重新创建对象)以执行相同的过程时,它不会在控件中显示已添加的项目.(我已正确放置了对象).

这时,Listbox.InvokeRequired变为false.然后,我通过调试检查了listBox,它在内部抛出了objectObjectException错误.

Hi,

1) Application Contains

MainForm:- which is Mainframe of Application.

BaseForm :- which contains controls e.g. ListBox

ChildForm1:- derived from BaseForm, which display Listbox

Worker_Thread:- which invokes and update ListBox items of Main_Thread Application.

2) Application Working:-

In MainFrame constructor, Thread is created and started running.

On MenuItem click of Mainform Application,
I create (BaseForm childform = new childForm1) Object and childForm1.show();

Using Workerthread, I invoked listbox control of mainform and added items into Listbox and it shown.
And When I close the form and reopen(recreate the object) to do the same procedure it doesnt show the added items into the control.(I have disposed the object properly).

At this time, Listbox.InvokeRequired becomes false. And I checked listBox through debugging, which was thrown disposedObjectException error internally.

推荐答案

写道:​​

我已经正确放置了对象





写道:​​

抛出了objectedObjectException错误

thrown disposedObjectException error



听起来您正在调用仍在使用的东西上的Dispose?

尼克



It sounds like you''re calling Dispose on something you''re still using?

Nick


这篇关于WinForms-控件上的MultiThreading InvokeRequired有时会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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