function OnPowerOff() { try { // Start the LED indicator to show that we're working DeviceControl.PowerLED = LED_BlinkSlow; // Grab the memory state before we tear everything down var MemoryState = TVShell.EventLog.SystemMonitor.MemoryState; // Turn off UI sounds DeviceControl.PlayMute = true; // Stop audio. StopDialingMusic(); DeviceControl.StopPlayingSound(); // Turn off the display DeviceControl.TVEncoder.OutputEnable = false; // Remove the active page TVShell.URL = "msntv:/Shell/PowerOff.html"; // Persist print setting TVShell.PrintManager.SaveObject(); // Switch to main panel PanelManager.Show("main"); // Turn off the screen saver and keep it from starting while // we are off. TVShell.ScreenSaver.Stop(); TVShell.ScreenSaver.Enable = false; // Remove all panels (except for main) RemoveAllPanels(PanelManager); // Sign out the current user TVShell.UserManager.ClearCurrentUser(); // If a user was authorized, then the MeterManager, PolicyManager, // and LoginManager would have already been cleaned up. // No need for metering TVShell.MeteringManager.Stop(); // Cleanup on PolicyManager and LoginManager TVShell.PolicyManager.Cleanup(); TVShell.LoginManager.Cleanup(); // CleanUp PhotoManager caches and temporary photos TVShell.PhotoManager.ClearThumbnailRequestQueue(); TVShell.PhotoManager.ClearImageResizeRequestQueue(); TVShell.PhotoManager.ClearTempPhotoDirectories(); // // The service is no longer connected // TVShell.ConnectionManager.ServiceState = Service_LoggedOff; // Unmount all shares and lose passwords that are mark as 'no save' if (HomeNetworking) HomeNetworking.PowerOff(); // Hangup TVShell.ConnectionManager.WANDisconnect(); TVShell.ConnectionManager.LANDisconnect(); // Clear the non-persistent service list TVShell.BuiltinServiceList.Clear(); // Remember power state TVShell.Init.PowerState = PowerState_Off; TVShell.Init.Save(); // Make sure all the ConnectionManager settings are saved and flushed to the bootrom ConnectionManagerSave(); var BootROM = new ActiveXObject("MSNTV.BootRom"); BootROM.Read(); BootROM.PowerOnState = false; BootROM.Flush(); // The threshold for memory to decide if we want to exit the browser while powering off is a litle higher (5MB) than Memory_low (2MB) var AvailVirtualMemory = TVShell.SystemInfo.AvailVirtualMemory; var AvailPhysicalMemory = TVShell.SystemInfo.AvailPhysicalMemory; var fReducedMemory = (AvailVirtualMemory > kReducedMemoryThreshold && AvailPhysicalMemory > kReducedMemoryThreshold) ? false : true; if (fReducedMemory) { TVShell.EventLog.Warning("Shell: system low on memory, browser exiting..."); RemovePanel(autopanel.name); setTimeout("QuitWhenComplete(0)",100); } else PowerOffWhenComplete(0); } catch (ex) { TVShell.Reboot(); } }