Application.Suspending 이벤트

정의

애플리케이션이 다른 상태에서 일시 중단됨 상태로 전환될 때 발생합니다.

public:
 virtual event SuspendingEventHandler ^ Suspending;
// Register
event_token Suspending(SuspendingEventHandler const& handler) const;

// Revoke with event_token
void Suspending(event_token const* cookie) const;

// Revoke with event_revoker
Application::Suspending_revoker Suspending(auto_revoke_t, SuspendingEventHandler const& handler) const;
public event SuspendingEventHandler Suspending;
function onSuspending(eventArgs) { /* Your code */ }
application.addEventListener("suspending", onSuspending);
application.removeEventListener("suspending", onSuspending);
- or -
application.onsuspending = onSuspending;
Public Custom Event Suspending As SuspendingEventHandler 

이벤트 유형

예제

이 코드 예제에서는 이 이벤트에 대한 일반적인 사용 패턴을 보여 줍니다. 이 코드는 app.xaml 파일에 대한 코드 숨김의 일부로 많은 XAML 샘플에서 사용됩니다. XAML 샘플을 찾아보는 경우 이 코드에서 참조하는 클래스 API의 SuspensionManager 소스 코드를 찾을 수 있습니다.

async protected void OnSuspending(object sender, SuspendingEventArgs args)
{
    SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();
    await SuspensionManager.SaveAsync();
    deferral.Complete();
}
Private Async Sub OnSuspending(sender As Object, args As SuspendingEventArgs) 
    Dim deferral As SuspendingDeferral = args.SuspendingOperation.GetDeferral 
    Await SuspensionManager.SaveAsync 
    deferral.Complete() 
End Sub 

설명

시스템은 사용자가 다른 앱 또는 데스크톱으로 전환할 때마다 앱을 일시 중단하고 사용자가 다시 전환할 때마다 앱을 다시 시작합니다. 그러나 시스템은 리소스를 확보하기 위해 일시 중단된 동안 앱을 종료할 수도 있습니다. 따라서 다음 작업을 수행하려면 Suspending 이벤트를 처리해야 합니다.

  • 사용자 세션 상태를 유지합니다.
  • 리소스에 대한 배타적 잠금을 해제합니다.
  • 가능하면 메모리 사용량을 줄입니다. 예를 들어 다시 활성화 시 개체 형식으로 재구성하기 쉬운 데이터를 직렬화합니다.
  • 앱 상태를 저장합니다. 일시 중단 이벤트는 종료 전에 앱이 수신할 수 있는 유일한 표시입니다(발생하는 경우). 이 때문에 활성화하는 동안 정확히 동일한 환경을 다시 만들 수 있는 충분한 세션 상태(예: 현재 문서를 읽거나 현재 동영상 재생 위치)를 저장해야 합니다. 콘텐츠 만들기 앱에 대한 지침은 사용자의 작업을 조기에 자주 저장하고 일시 중단 중에 최종 저장을 커밋하는 것입니다. 일시 중단 이벤트 처리기에 작업을 완료하는 데 5초밖에 가지 않으므로 일시 중단 전에 데이터를 저장하는 것이 유용합니다.

앱이 종료되면 OnLaunched 메서드 재정의에서 앱 상태를 복원할 수 있습니다. 앱이 종료되기 전에 다시 시작되면 시스템은 앱 상태를 자동으로 복원합니다. 뉴스 피드 또는 사용자의 위치와 같이 앱이 일시 중단된 동안 변경되었을 수 있는 표시된 콘텐츠를 새로 고쳐야 하는 경우에만 Resuming 이벤트를 처리해야 합니다.

Suspending 이벤트는 등록된 동일한 아파트에서 실행됩니다.

적용 대상

추가 정보