我目前正在采用现有设计并对其某些方面进行重构。我试图将BackgroundWorker类包装在单独的对象中,并在单独的线程上调用数据导入。我唯一的问题是让StatusStrip对象在窗体上更新。该应用程序使用了Reflections,并且在包装导入例程时已经考虑了这一点。至此,我已经消除了所有交叉线程。我已将用于将StatusStrip更新的回调从Form重定向到此包装对象,并且数据导入正在回调包装器。表单中有一个用于处理原始回调的方法。我只需要弄清楚如何跨线程调用更新。
异步操作部分在很大程度上是由于我从stackoverflow获得的信息而工作的。除了这个愚蠢的StatusStrip之外,所有的一切都已连接起来。
答案 0 :(得分:0)
所以,它解决了。
如果在BackgroundWorker包装器类中被调用,则按照Nick的建议执行以下操作:
relation
注意:MainForm.updtStatus是Form上的原始事件,数据导入已调用该事件以更新StatusStrip。
我在另一个stackoverflow线程上发现了这一点
New property name (press <return> to stop adding fields):
> user
Field type (enter ? to see all types) [string]:
> relation
What class should this entity be related to?:
> User
What type of relationship is this?
------------ ----------------------------------------------------------------
Type Description
------------ ----------------------------------------------------------------
ManyToOne Each Statement relates to (has) one User.
Each User can relate/has to (have) many Statement objects
OneToMany Each Statement relates can relate to (have) many User objects.
Each User relates to (has) one Statement
ManyToMany Each Statement relates can relate to (have) many User objects.
Each User can also relate to (have) many Statement objects
OneToOne Each Statement relates to (has) exactly one User.
Each User also relates to (has) exactly one Statement.
------------ ----------------------------------------------------------------
Relation type? [ManyToOne, OneToMany, ManyToMany, OneToOne]:
> ManyToOne
Is the Statement.user property allowed to be null (nullable)? (yes/no) [yes]:
> yes
Do you want to add a new property to User so that you can access/update Statement objects from it - e.g. $user->getStatements()? (yes/no) [yes]:
> yes
A new property will also be added to the User class so that you can access the related Statement objects from it.
New field name inside User [statements]:
>
updated: src/Entity/Statement.php
updated: src/Entity/User.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
然后,我在BackgroundWorker包装器的顶部修改了我的代码的委托:
private void updtStatus(object sender, EventArgs e)
{ if (MainForm.InvokeRequired)
{ MainForm.Invoke(new DoUIWorkHandler(MainForm.updtStatus), new object[] { sender, e }); }
}
这是我所缺少的代表作品!奇迹般有效!感谢您在此问题上的所有帮助。