使用MVP架构BackgroundWorker的最佳实践的WinForms [英] Best Practice for BackGroundWorker in WinForms using an MVP architecture
问题描述
我工作的一个WinForms项目。我采取的MVP架构。我有一些处理密集型作业在演示运行(从文件系统读取和到一个数据库进行批量插入)。我想在后台线程不会对我的看法(进度条,和datagridview的)锁定UI和更新的控制来执行这些操作。
I am working on a winforms project. I am implementing an MVP architecture. I have some processing intensive jobs running at the presenter (Reading from file system and performing bulk inserts to a DB). I would like to perform these operations in a background thread without locking up the UI and update controls on my view (progress bar, and datagridview).
如果我只是访问我的演讲中的BackgroundWorker对象,并处理它通过让视图的事件处理程序触发演示是听??事件是在主持人的事件。
Should I just access the backgroundworker object within my presenter and handle it's events in the presenter by having the view event handlers trigger events that the presenter is listening to??
例如:
在VIEW:
private void backgroundWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
if (WorkerProgressChange != null)
{
WorkerProgressChange(this, EventArgs.Empty);
}
}
在主讲人:
_view.WorkerProgressChange += UpdateView;
这个问题似乎合理?有人可以提供一个更好的模式?
Does this seem reasonable? Can someone offer a better model?
谢谢!
推荐答案
工作不应该由主持人召唤 - 补充一点,做的工作的另一个示范单位,并拨打该工作(可通过GUI)从控制器
Work should not be summoned by the presenter - add another model unit that does the work and call the work (can be via the gui) from the controller.
(有看法提高工作的事件,由控制器,它召唤的BackgroundWorker,并呼吁更新/完成)的观点来处理。
(Have the view raise a Work event, handled by the controller, which summons the backgroundworker and calls the view on updates/completion).
这篇关于使用MVP架构BackgroundWorker的最佳实践的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!