Windows Phone 7 handles sleep and tombstone Restoration

Source: Internet
Author: User

WP7ProgramAs shown in:

The sleep state and the tombstone state are confusing. The program stops running during sleep state, but the difference is that the entire process still exists in the memory. When this program is restored, you do not need to create a new instance. In this way, the program recovery and switching are accelerated, and we do not need to restore the tombstone data from the sleep state. Generally, when you click the Home key, the program enters the sleep state. When the current program is running, the system will execute some operations to release the memory when the memory is insufficient or insufficient to allow the program to run smoothly, in this case, the program may change from the sleep state to the tombstone state. When a program enters the tombstone state, its process is terminated, but the information in the program's rollback stack and some information we save will be kept in the memory.

The activated event in the application class is triggered when the program recovers. We can check the isapplicationinstancepreserved parameter to determine whether the program returns from the sleep or tombstone status, in this method, we can use it to restore the data previously stored in the deactivated event.

ProcessedCodeAs follows:

Private VoidApplication_activated (ObjectSender, activatedeventargs E)
{
If(E. isapplicationinstancepreserved)
{
//Restore from sleep state
}
Else
{
//Restore from the tombstone status
//At this time, the program's information in the memory has been cleared, and you need to process how to restore your previous data here
}
}

 

You can set the settings on vs to restore the tombstone status of the debugging program. The settings are as follows:

 

When we recover from sleep to the program, if we are sending an HTTP request in the program, this request may be canceled, at this time, we need to capture and handle this exception in the program. The processing code is as follows:

Private   Void Getsomeresponse (iasyncresult myresultasync)
{
Httpwebrequest request = (httpwebrequest) myresultasync. asyncstate;
Try
{
Httpwebresponse response = (httpwebresponse) request. endgetresponse (myresultasync );
If (Response. statuscode = httpstatuscode. OK & response. contentlength> 0 )
{
Using (Streamreader sr =New Streamreader (response. getresponsestream ()))
{
// ......
}
}
}
Catch (Webexception E)
{

If (E. Status = webexceptionstatus. requestcanceled)
// This may be returned from sleep and tombstone status.
// Here, we can process the restoration of sleep and tombstone status, for example, re-sending an HTTP request ......
Else
{
// Other exceptions
Using (Httpwebresponse response = (httpwebresponse) E. Response)
{
MessageBox. Show (response. statuscode. tostring ());
}
}
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.