/// <summary> /// 在将要挂起应用程序执行时调用。 在不知道应用程序 /// 无需知道应用程序会被终止还是会恢复, /// 并让内存内容保持不变。 /// </summary> /// <param name="sender">挂起的请求的源。</param> /// <param name="e">有关挂起请求的详细信息。</param> private async void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); //TODO: 保存应用程序状态并停止任何后台活动 await ExtendedExecutionHelper.OnSuspendingAsync(); deferral.Complete(); }
private void OnResuming(object sender, object e) { ExtendedExecutionHelper.OnResuming(); }
private async void StartButton_Click(object sender, RoutedEventArgs e) { var loader = new ResourceLoader(); if (!int.TryParse(portBox.Text, out int port)) { NotifyUser(loader.GetString(PortIncorrect)); return; } var allowAnonymous = allowAnonymousBox.IsChecked == true; string userName = userNameBox.Text; string password = passwordBox.Text; var settings = ApplicationData.Current.LocalSettings; settings.Values[PortNumberSetting] = port; settings.Values[AllowAnonymousSetting] = allowAnonymous; settings.Values[UserNameSetting] = userName; settings.Values[PasswordSetting] = password; var x = VisualStateManager.GoToState(this, nameof(runningState), true); statusBlock4.Text = string.Format(loader.GetString(Ipv4Listening), port); statusBlock6.Text = string.Format(loader.GetString(Ipv6Listening), port); cts = new CancellationTokenSource(); IPEndPoint ep4 = new IPEndPoint(IPAddress.Any, port); IPEndPoint ep6 = new IPEndPoint(IPAddress.IPv6Any, port); await Task.Run(() => { if (allowAnonymous) { server4 = new FtpServer( ep4, new UwpFileProviderFactory(rootPath), new Zhaobang.FtpServer.Connections.LocalDataConnectionFactory(), new Zhaobang.FtpServer.Authenticate.AnonymousAuthenticator()); server6 = new FtpServer( ep6, new UwpFileProviderFactory(rootPath), new Zhaobang.FtpServer.Connections.LocalDataConnectionFactory(), new Zhaobang.FtpServer.Authenticate.AnonymousAuthenticator()); } else { server4 = new FtpServer( ep4, new UwpFileProviderFactory(rootPath), new Zhaobang.FtpServer.Connections.LocalDataConnectionFactory(), new Zhaobang.FtpServer.Authenticate.SimpleAuthenticator(userName, password)); server6 = new FtpServer( ep6, new UwpFileProviderFactory(rootPath), new Zhaobang.FtpServer.Connections.LocalDataConnectionFactory(), new Zhaobang.FtpServer.Authenticate.SimpleAuthenticator(userName, password)); } server4.Tracer.UserConnected += Tracer_UserConnected; server6.Tracer.UserConnected += Tracer_UserConnected; server4.Tracer.CommandInvoked += Tracer_CommandInvoked; server6.Tracer.CommandInvoked += Tracer_CommandInvoked; server4.Tracer.ReplyInvoked += Tracer_ReplyInvoked; server6.Tracer.ReplyInvoked += Tracer_ReplyInvoked; server4.Tracer.UserDisconnected += Tracer_UserDisconnected; server6.Tracer.UserDisconnected += Tracer_UserDisconnected; }); var server4Deferral = ExtendedExecutionHelper.GetDeferral(); server4Run = server4.RunAsync(cts.Token).ContinueWith(async t => await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (t.IsFaulted) { statusBlock4.Text = string.Format(loader.GetString(Ipv4Error), t.Exception); } else { statusBlock4.Text = loader.GetString(Ipv4Stopped); } server4Deferral.Complete(); })); var server6Deferral = ExtendedExecutionHelper.GetDeferral(); server6Run = server6.RunAsync(cts.Token).ContinueWith(async t => await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (t.IsFaulted) { statusBlock6.Text = string.Format(loader.GetString(Ipv6Error), t.Exception); } else { statusBlock6.Text = loader.GetString(Ipv6Stopped); } server6Deferral.Complete(); })); }