我正在培养我的乐团音乐家多年。 我曾遇到一个问题,即“光线”在它被闲置后恢复,时间不确定。 然而,如果音乐家玩.,照相机的运行完全是罚款的。 坠机发生时, app子在闲置后又重新成为焦点。 我不能稳定地照搬坠机,但这次坠机确实是时候了。 我不知道需要多长时间。
我曾试图通过附上一小小gger来诊断这一问题,但坠毁的拖.是在 attached后发生的。 在<条码>级应用:应用程序代码>上,我添加了<条码>Resuming、<代码>Suspending和 UnhandledException
方法,但还是用斜线标示坠毁原因。
我对如何进一步解决这一问题感到悲痛。 任何关于下一步应采取哪些步骤或如何适当利用diagnose和避免这种坠毁的建议都将受到高度赞赏。
这是我音乐家守则的一部分。
public class MusicPlayer : IMusicEventListener
{
public static MediaPlaybackState PlaybackState => Player.PlaybackSession.PlaybackState;
public static bool IsPlaying => PlaybackState == MediaPlaybackState.Playing;
public static Playlist NowPlaying => new Playlist(MenuFlyoutHelper.NowPlaying, CurrentPlaylist);
private static MediaPlaybackList PlaybackList = new MediaPlaybackList() { MaxPlayedItemsToKeepOpen = 1 };
public static MediaPlayer Player = new MediaPlayer() { Source = PlaybackList };
}
其部分内容是我的应用等级法典。
sealed partial class App : Application
{
public static bool Inited { get; private set; } = false;
public static List<Action> LoadedListeners = new List<Action>();
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.Resuming += App_Resuming;
this.UnhandledException += App_UnhandledException;
}
private void App_Resuming(object sender, object e)
{
Debug.WriteLine($"sender {sender.GetType()} e {e}");
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
OnLaunched(e, null);
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
try
{
TileHelper.ResumeTile();
ToastHelper.HideToast();
Save();
SQLHelper.ClearInactive();
}
catch (Exception ex)
{
Log.Warn($"OnSuspending exception {ex}");
}
deferral.Complete();
}
public static async void Save()
{
SettingsHelper.Save();
MusicPlayer.Save();
await Helper.ClearBackups(10);
}
protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
var deferral = args.TaskInstance.GetDeferral();
switch (args.TaskInstance.Task.Name)
{
case ToastHelper.ToastTaskName:
if (args.TaskInstance.TriggerDetails is Windows.UI.Notifications.ToastNotificationActionTriggerDetail details)
{
// Perform tasks
if (Enum.TryParse(typeof(ToastButtonEnum), details.Argument, out object toastButton))
{
try
{
HandleBackgroundActivation((ToastButtonEnum)toastButton);
}
catch (Exception e)
{
Log.Warn($"HandleBackgroundActivation failed {e}");
}
}
}
break;
}
deferral.Complete();
}
private async void HandleBackgroundActivation(ToastButtonEnum toastButton)
{
switch (toastButton)
{
case ToastButtonEnum.Next:
MusicPlayer.MoveNext();
if (MusicPlayer.PlayMode == PlayMode.RepeatOne)
{
ToastHelper.HideToast();
await ToastHelper.ShowToast(MusicPlayer.CurrentMusic, MusicPlayer.PlaybackState);
}
break;
case ToastButtonEnum.Pause:
MusicPlayer.Pause();
break;
case ToastButtonEnum.Play:
MusicPlayer.Play();
break;
case ToastButtonEnum.SwitchLyricsSourceToMusic:
await ToastHelper.SwitchLyricsSource(LyricsSource.Music);
break;
case ToastButtonEnum.SwitchLyricsSourceToLrcFile:
await ToastHelper.SwitchLyricsSource(LyricsSource.LrcFile);
break;
case ToastButtonEnum.SwitchLyricsSourceToInternet:
await ToastHelper.SwitchLyricsSource(LyricsSource.Internet);
break;
}
}
protected override async void OnFileActivated(FileActivatedEventArgs args)
{
base.OnFileActivated(args);
Music music = await Music.LoadFromPathAsync(args.Files[0].Path);
Log.Info("activate file " + args.Files[0].Path);
if (music == null)
{
Helper.ShowButtonedNotification("CannotReadLocalMusicFile", "Authorize", async (n) =>
{
await StorageHelper.AuthorizeFolder();
});
return;
}
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
MusicPlayer.AddNextAndPlay(music);
}
else
{
OnLaunched(null, music);
}
}
private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
Log.Error("App_UnhandledException {0}", e.Exception);
}
}