从另一个线程更新大型模型 [英] Updating a large model from another thread

查看:74
本文介绍了从另一个线程更新大型模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序是一种测试平台,首先是通过SSH连接到两个嵌入式Linux。连接后,它会启动测试并检索数据。测试很长,所以我使用了一个启动多个线程的BackgroundWorker。

My program is a kind of test bench which starts by reaching two embedded Linux through SSH. Once connected, it launches tests and retrieve data. The tests are quite long so I'm using a BackgroundWorker which launches multiple threads.

我有一个模型和子模型,它们都实现了INotifyPropertyChanged并更新了视图,但我知道这不是从另一个线程更新模型的最佳方法,因为PropertyChanged回调将由工作线程执行。 

I have a model and submodel which all implement INotifyPropertyChanged and update the view but I understand this is not the best way to update the model from another thread since the PropertyChanged callback will be executed by worker threads. 

这是最糟糕的,因为我有一个包含我的测试序列的OberservableCollection,每个序列都有包含其他数据的ObservableCollection。

This is even worst since I have an OberservableCollection containing my test sequences and each sequence has an ObservableCollection containing other data.

每次我想更新模型时,我都可以使用在UI线程中执行的委托但是,我不能使用刚刚由我的工作人员更新的数据线程,因为我不知道UI线程何时更新了模型。

I could use a delegate executed in the UI thread each time I want to update the model but then, I can't use the data just updated by my worker thread since I don't know when the UI thread has updated the model.

我看到的唯一方法是有一个线程安全模型通知我的UI模型。每次我在线程安全模型中添加/删除/修改某些内容时,都会调用UI线程中的委托来更新UI模型,但之后我需要两个几乎相同的模型。

The only way I see is to have a thread safe model which notify my UI model. And each time I add/remove/modify something in my thread safe model, a delegate in the UI thread is called to update the UI model but then I need two almost identical model.

有你是个好主意,我错过了什么?

Have you a better idea, I'm missing something ?

推荐答案

你好iSlandW,

Hi iSlandW,

>>你有更好的想法,我错过了什么吗?

>>Have you a better idea, I'm missing something ?

也许你可以考虑进行异步编程。 

Maybe you could consider an async Programming. 

欲了解更多信息,请参阅:

For more information, please refer to:

https://msdn.microsoft.com/en-us/magazine/dn605875.aspx?f=255&MSPPError=-2147217396

祝你好运,

张龙


这篇关于从另一个线程更新大型模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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