你应该把它放在 OnLaunched 方法中,你只需要确定在哪里。
 protected async override void OnLaunched(LaunchActivatedEventArgs args)
    {
        var rootFrame = new Frame();
        // Do not repeat app initialization when already running, just ensure that
        // the window is active
        if (args.PreviousExecutionState == ApplicationExecutionState.Running)
        {
           //....
        }
        if (args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
        {
            /....
        }
        if (!String.IsNullOrEmpty(args.Arguments))
        {
                //....
        }
        if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //....
        }
        if (args.PreviousExecutionState == ApplicationExecutionState.NotRunning)
        {
            //.....
        }
        TileUpdateManager.CreateTileUpdaterForApplication().Clear();
        BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
        SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
        // Create a Frame to act navigation context and navigate to the first page
        if (!rootFrame.Navigate(typeof(MainPage)))
        {
            throw new Exception("Failed to create initial page");
        }
        // Place the frame in the current Window and ensure that it is active
        Window.Current.Content = rootFrame;
        Window.Current.Activate();
    }
如果您查看代码,您的应用程序关闭/暂停的原因有多种。因此,确定在哪些情况下要运行解码代码以更新动态磁贴中的数字,将其放在 if 中,它应该可以工作。