我应该何时从 Windows Phone 7 的独立存储加载数据?

发布于 2024-10-06 02:32:10 字数 313 浏览 0 评论 0原文

Microsoft 的最佳实践指出:

如果应用程序依赖于独立存储中的数据,则不应在 Launching 事件处理程序或 Activated 事件处理程序中加载此数据。磁盘操作可能需要几秒钟的时间,并且在加载和激活应用程序之前调用这些事件,因此在这些处理程序中访问隔离存储会导致应用程序加载时等待很长的时间。相反,您应该在加载应用程序后从独立存储异步加载数据。

为什么会这样?什么时候应该从隔离存储中读取数据?

我想要加载的是电话用户是否将其用户名/密码保存到独立存储中,并预加载这些用户名/密码以在第一个屏幕上登录。该行动应何时进行?

谢谢, 标记

Microsoft's best practices state:

If an application relies on data from isolated storage, you should not load this data in the Launching event handler or in the Activated event handler. Disk operations can take several seconds and these events are called before the application is loaded and active, so accessing Isolated Storage in these handlers results in a long wait time as the application loads. Instead, you should load data from Isolated Storage asynchronously, after the application has loaded.

Why is this, and when should data be read from isolated storage?

What I'm looking to load is if the phone user has their username/password persisted to isolated storage, and preloading those for login on the first screen. When should this action take place?

thanks,
Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

厌味 2024-10-13 02:32:11

首先,不要存储密码。曾经!任何地方!存储密码的加盐哈希值。如果您需要存储此信息以传递给 Web 服务(或类似服务),请让 Web 服务在成功登录时返回一个令牌并存储该令牌。

现在,你的实际问题。
不过,您自己已经回答了第一部分。

因为您希望应用程序具有响应能力,所以当应用程序启动时,您应该在 UI 线程之外及时执行操作。

数据应在最适合应用程序、数据量以及需要或更新的频率的时间从隔离存储加载和保存到隔离存储。

在您的特定实例中,我不认为从独立存储中检索 2 个字符串会非常慢,因此我将在相关页面的 Loaded() 事件中执行它们的检索。

如果您只是检索用户名和密码,我会考虑使用 IsolatedStorageSettings 来保存这些。

如果您还有许多其他详细信息需要存储,并且大约在同一时间需要这些信息,您可能希望将它们全部存储在一起,以便可以一起检索它们。

Firstly, don't store the password. Ever! Anywhere! Store a salted hash of the password. If you need to store this to pass to a webservice (or similar) have the webservice return a token on successful login and store that instead.

Now, your actual question.
You've answered the first part of it yourself though.

Because you want the application to be responsive, when the application launches you should perform timely operations off of the UI thread.

Data should be loaded from and saved to IsolatedStorage at times which are most appropriate to the application, the volume of data and the frequency with which it is needed or updated.

In your specific instance, I wouldn't expect the retrieval of 2 strings from isolated stroage to be very slow at all and so I would perform their retrieval in the Loaded() event of the page in question.

If you were just retrieving a username and password I would consider using IsolatedStorageSettings to persist these.

If you also had lots of other details to store and needed these at about the same time you may want to store them all together so you could retrieve them all together.

泡沫很甜 2024-10-13 02:32:11

将独立存储中的数据加载推迟到应用程序加载之后进行异步加载的动机有两个。

  1. 要在这些资源受限的设备上加载应用程序需要做大量工作。如果您的应用程序这样做可行,那么将任何操作推迟到应用程序响应之后将改善用户体验。另请注意,您的证书请求需要 5 秒才能显示内容,20 秒才能响应 - 并且某些设备比其他设备更慢/更快。

  2. 异步适用于任何重要的操作,这样您就不会阻塞 UI 线程并干扰并导致设备显示为未完全响应。

值得记住的是,除了正常的低负载测试场景之外,手机可能还会在后台执行您未考虑过的操作(例如同步邮件)。

我同意 Matt 的观点,为了登录凭据而加载 2 个字符串可能不会给您带来性能问题。

如果您想非常勤奋,您可以在加载登录页面后异步加载该数据,并禁用控件,直到检索该数据为止。

The motivation to defer loading of data from isolated storage until the app is loaded, and to do it asycnrhonously is two-fold.

  1. There is a lot of work being done to load the app on these resource constrained devices. If it's practical for your app to do so, then defering any actions until after the app is responsive will improve the user experience. Noting also that you have a cert reqt of 5s to show something and 20s to be responsive - and some devices are slower/faster than others.

  2. Async is good for any non trivial operations so that you don't block the UI thread and interfere and cause the device to appear not fully responsive.

It's worth keeping in mind that the phone may be doing things you haven't considered in the background in additional to your normal low load testing scenarios - such as syncing mail.

I concur with Matt, that loading 2 strings, for the sake of login credentials, is probably not going to cause you a performance issue.

If you wanted to be ultra diligent, you could load that data asynchronously after the login page is loaded and have the controls disabled until such time as that data is retrieved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文