Share via


Windows Embedded Compact 7: How to Exit a Silverlight for WindowsEmbedded Application Gracefully

To conserve system resources and maintain overall system stability, it is important for any application to exit gracefully. To ensure that your Silverlight for Windows Embedded application exits gracefully, you use the EndDialog method of the visual host object, IXRVisualHostPtr.

In this article:

Graceful Exit

A graceful exit is one in which the application’s automatic cleanup routines are executed prior to the application being unloaded from memory. Use the EndDialog method of the visual host to exit a Silverlight for Windows Embedded application gracefully.

How to exit the application gracefully

  1. Add the following code to your application source:

    void ExitApplication()
    {
        IXRVisualHostPtr pHost = NULL;
        HRESULT hr = App::GetVisualHost(&pHost);
        
        if ( pHost )
        {
            pHost->EndDialog(0);
        }
    }
  2. Call the ExitAppliction() method to exit the application gracefully.