加载大量前期数据..同步或异步. [英] Loading lots of upfront data. . sync or async .

查看:26
本文介绍了加载大量前期数据..同步或异步.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 winforms 应用程序,它在启动时同步下载一组数据.这显然需要一段时间,但是当任何服务或 GUI 类加载时,它们都会有这些数据.我可以将其更改为放在后台线程上,但是每个需要访问此数据的组件都必须在此数据准备好时不断收到通知.对于我的每一个依赖于要加载的数据进行 If (Loaded) 检查或必须订阅加载事件的类来说,这似乎都是糟糕的设计...有什么想法吗?

so i have a winforms apps that downloads a set of data syncronously on startup. This obviously takes a while but then when any of the services or GUI classes load, they all have this data. I could change this to put on a background thread but then every component that needs access to this data would continuously have to get notified when this data was ready. This seems like bad design for every one of my classes that depends on this data to be loaded to have a If (Loaded) check or have to subscribe to a loaded event . . . any ideas?

还有其他想法吗?

推荐答案

我已经编写了许多与您描述的行为具有相似行为的应用程序,并为您提供了三个建议......

I've written a number of applications that have similar behaviour to what you describe, and have three suggestions for you ...

启动画面

向您的应用程序添加启动画面,显示多个启动步骤的状态.过去,当应用程序在启动时必须执行许多步骤时,在用户开始使用应用程序之前,我曾使用此方法 - 通过 Active Directory 确认身份和访问授权,系统信息的联系人数据库,加载静态数据、与指定网络服务的初步联系、检查先决条件(如 Crystal 报表)是否已安装和工作等.

Add a splash screen to your application that displays the status of a number of startup steps. I've used this in the past when an application has a number of steps that have to occur on startup, before the user gets to use the application - confirmation of identity and authorisation of access through Active Directory, contact database for system information, loading static data, initial contact with specified web services, checking that prerequisites (like Crystal reports) are installed and working, etc etc.

订阅

让每个组件向您的数据加载器注册,并在数据可用时收到通知.这是观察者模式,没有错,尽管管理订阅可能有点麻烦.

Have each component register interest with your data loader, and be notified when the data is available. This is the observer pattern, nothing wrong with it, though managing the subscriptions can be a bit messy.

延迟加载

设计应用程序的其余部分以尽可能晚地请求数据,为后台加载提供尽可能多的机会来完成.启动后快速跑题的用户必须等待必要的数据加载;花时间(也许他们启动应用程序然后切换到 Outlook)的用户发现响应是即时的.

Design the rest of your application to request the data as late as possible, giving as wide an opportunity for background loading to complete as possible. Users who are quick off the mark after startup have to wait for necessary data to load; users who take their time (maybe they started the application and then switched to Outlook) find response is immediate.

这篇关于加载大量前期数据..同步或异步.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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