简体   繁体   English

在App.xaml.cs中创建变量或在WP7中使用PhoneApplicationService.state之间的区别?

[英]Difference between creating variables in App.xaml.cs or using PhoneApplicationService.state in WP7?

I've seen examples and they seem to be used interchangebly. 我看过示例,它们似乎可以互换使用。 Is there benefits from using one method over the other? 使用一种方法比使用另一种方法有好处吗? Also does performance play a factor between the two? 绩效在两者之间起着重要作用吗?

One big difference is that the runtime automatically saves the PhoneApplicationService.State Dictionary when the app is tombstoned. 一个很大的不同是,当应用程序被逻辑删除时,运行时会自动保存PhoneApplicationService.State字典。 If you have global variables in App.xaml.cs instead, you'll have to handle the saving and restoring of this data yourself. 如果在App.xaml.cs中有全局变量,则必须自己处理此数据的保存和还原。

I am not aware of any performance implications of one method compared to the other, but since you're handling the serialization of data yourself in case of the global variables, the performance will be as good (or bad) as the code you write for performing the serialization. 我不知道一种方法与另一种方法相比对性能有何影响,但是由于您是在全局变量的情况下自己处理数据的序列化,因此性能将与编写的代码一样好(或不好)执行序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM