void task_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) { }
public MainPage() { InitializeComponent(); NavigationCacheMode = NavigationCacheMode.Enabled; //这个计时器用于定时请求pre-check 每逢分钟的0 5进行一次请求,数据放入数据库中 DispatcherTimer timer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 1) }; //倒计时间隔1s timer.Tick += new EventHandler <object>(async(sender, e) => { await Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { //https://github.com/hddevteam/ServerMonitor-for-UWP.git var time = DateTime.Now.Minute; var s = DateTime.Now.Second; if (time % 5 == 0 && s == 0) { MainPageViewModel.Pre_Check(); //执行pre check int text = 0; cdtxt.Text = text.ToString("00:00"); } else { var min = DateTime.Now.Minute; var sec = DateTime.Now.Second; var dmin = 4 - (min % 5); var dsec = 60 - sec; if (dsec == 60) { dsec = 0; dmin = dmin + 1; } cdtxt.Text = (dmin).ToString("00") + ":" + (dsec).ToString("00"); } })); }); timer.Start(); //在这里启动后台定时十五分钟请求 var builder = new BackgroundTaskBuilder(); builder.Name = "backgroud request"; //进程内的name 用于标识任务内容即可 builder.SetTrigger(new TimeTrigger(15, false)); //用法在官方文档表明,15表示间隔,不能更少,否则会抛出异常,false代表不是一次 BackgroundTaskRegistration taskRegistration = builder.Register(); //注册后台服务 //int i = 0; //int TimeCount = 300;//倒计时秒数 //DispatcherTimer timer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 1) };//倒计时间隔1s //timer.Tick += new EventHandler<object>(async (sender, e) => //{ // await Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => // { // //https://github.com/hddevteam/ServerMonitor-for-UWP.git // i += 1; // //double temp = (90 * Math.PI) * i / TimeCount / 10; // cdtxt.Text = ((TimeCount - i) / 60).ToString("00") + ":" + ((TimeCount - i) % 60).ToString("00"); // if (i == TimeCount) // { // MainPageViewModel.Pre_Check();//执行pre check // i = 0; // } // })); //}); //timer.Start(); this.Loaded += MainPage_Loaded; }
void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine("Bgt " + sender.TaskId + " Completed..."); deferral.Complete(); }
private void A_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine("---------Completed!---------"); }
static public async void Register() { try { UnregisterBackgroundTasks(); // Internet Availble if (!IsRegistered(whirlMonWatchedTaskName)) { var builder = new BackgroundTaskBuilder(); builder.Name = whirlMonWatchedTaskName; builder.TaskEntryPoint = "WhirlMonWatchedTask.MainBackground"; builder.SetTrigger(new SystemTrigger(SystemTriggerType.InternetAvailable, false)); builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync(); backTask = builder.Register(); } // Timer if (!IsRegistered(whirlMonWatchedTaskName2)) { var builder = new BackgroundTaskBuilder(); builder.Name = whirlMonWatchedTaskName2; builder.TaskEntryPoint = "WhirlMonWatchedTask.MainBackground"; TimeTrigger minTrigger = new TimeTrigger(15, false); builder.SetTrigger(minTrigger); builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync(); backTask = builder.Register(); } // Toast Task if (!IsRegistered(whirlMonToastTaskName)) { var builder = new BackgroundTaskBuilder(); builder.Name = whirlMonToastTaskName; builder.TaskEntryPoint = "WhirlMonWatchedTask.ToastBackground"; builder.SetTrigger(new ToastNotificationActionTrigger()); builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync(); backTask = builder.Register(); } } catch (Exception x) { WhirlPoolAPIClient.ShowToast("Register Background Task:" + x.Message); } return; }
private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) => _deferal.Complete();
private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { BackgroundMediaPlayer.Shutdown(); _deferral.Complete(); }
private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Task_Completed)}"); }
private void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { library.IsPlaying = false; //MobileDebug.Service.WriteEvent("TaskCompleted"); Cancel(); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif AppShell shell = await PrepareAppShellAsync(e.PreviousExecutionState); // Back to the first(home) page if the app already have pages while (shell.AppFrame.CanGoBack) { shell.AppFrame.GoBack(); } if (shell.AppFrame.Content == null) { shell.AppFrame.Navigate(typeof(BooruViewer.Views.HomePage), e.Arguments); } // Handle the launch from a toast var queryString = QueryString.Parse(e.Arguments); if (queryString.TryGetValue("action", out string action)) { switch (action) { case "viewPost": break; default: break; } } CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; // Ensure the current window is active Window.Current.Activate(); AppSettings.Current.ScreenHeight = DisplayInformation.GetForCurrentView().ScreenHeightInRawPixels; AppSettings.Current.ScreenWidth = DisplayInformation.GetForCurrentView().ScreenWidthInRawPixels; // Update Tags if (TagDataBase.AllTags.Count == 0) { try { await TagDataBase.DownloadLatestTagDBAsync(); } catch (Exception ex) { //new MessageDialog(ex.Message).ShowAsync(); } } // TODO: reenable after debug BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = "ToastActionTask", //TaskEntryPoint = "RuntimeComponent1.NotificationActionBackgroundTask" }; builder.SetTrigger(new ToastNotificationActionTrigger()); BackgroundTaskRegistration registration = builder.Register(); }
private void Task_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) { Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Task_Progress)} - {args.InstanceId} : {args.Progress}"); }
public async Task StartListenerAsync() { try { _datagramSocket = new DatagramSocket(); var window = CoreWindow.GetForCurrentThread(); var dispatcher = window.Dispatcher; _backgroundTaskRegistration = (BackgroundTaskRegistration)_backgroundTaskService.FindRegistration <SocketActivityTriggerBackgroundTask>(); if (_backgroundTaskRegistration == null) { _backgroundTaskRegistration = await _backgroundTaskService.Register <SocketActivityTriggerBackgroundTask>(new SocketActivityTrigger()); } if (_backgroundTaskRegistration != null) { _datagramSocket.EnableTransferOwnership(_backgroundTaskRegistration.TaskId, SocketActivityConnectedStandbyAction.DoNotWake); } await _datagramSocket.BindServiceNameAsync(_applicationDataService.GetSetting <string>("UdpPort")); _datagramSocket.MessageReceived += async(s, e) => { uint stringLength = e.GetDataReader().UnconsumedBufferLength; var incomingMessage = e.GetDataReader().ReadString(stringLength); var package = JsonConvert.DeserializeObject <Package>(incomingMessage); if (package != null) { switch ((PayloadType)package.PayloadType) { case PayloadType.Discovery: package = new Package() { PayloadType = (int)PayloadType.Room, Payload = new Room() { RoomGuid = _applicationDataService.GetSetting <string>("Guid"), RoomName = _applicationDataService.GetSetting <string>("RoomName"), RoomNumber = _applicationDataService.GetSetting <string>("RoomNumber"), Occupancy = _applicationDataService.GetSetting <int>("ActualOccupancy"), IsIoT = _iotService.IsIotDevice() } }; var json = JsonConvert.SerializeObject(package); await _transmissionControlService.SendStringData(e.RemoteAddress, _applicationDataService.GetSetting <string>("TcpPort"), json); break; case PayloadType.PropertyChanged: break; default: break; } } }; } catch (Exception ex) { SocketErrorStatus webErrorStatus = SocketError.GetStatus(ex.GetBaseException().HResult); } _eventAggregator.GetEvent <PortChangedEvent>().Subscribe(async() => { await StartListenerAsync(); }); }
private void OnRegisteredTaskProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) => OnTaskProgress((int)args.Progress);
private void OnRegisteredTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) => OnTaskCompleted();
private static void BgTask_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) { LogMessage("BgTask Progress: " + args.Progress, NotifyType.StatusMessage); }
private void Btr_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { isUpdateCompleted = true; }
private static void BgTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { LogMessage("BgTask Completed", NotifyType.StatusMessage); }
//--------------------------------------------------------Events:---------------------------------------------------------------------\\ #region --Events-- private static void OnBackgroundTaskRegistrationCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { sender.Completed -= OnBackgroundTaskRegistrationCompleted; Logger.Info("Registered " + sender.Name + " background task."); }
/// <summary> /// Indicate that the background task is completed. /// </summary> void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine($"MyBackgroundAudioTask {sender.TaskId} Completed..."); deferral.Complete(); }
private void TaskOnProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) { Debug.WriteLine($"Background {sender.Name} TaskOnProgress."); }
private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { TaskCompleted?.Invoke(sender, args); }
private void TaskOnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine($"Background {sender.Name} TaskOnCompleted."); }
private void A_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) { Debug.WriteLine("---------Processing...---------"); }
/// <summary> /// 指示后台任务结束 /// </summary> private void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { DebugWrite("BackgroundAudioTask " + sender.TaskId + " Completed...", "BackgroundPlayer"); deferral.Complete(); }
/// <summary> /// Indicate that the background task is completed. /// </summary> void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { deferral.Complete(); }
private void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { }
async void task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine(sender.Name); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif AppShell shell = Window.Current.Content as AppShell; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (shell == null) { // Create a Frame to act as the navigation context and navigate to the first page shell = new AppShell(); //Associate the frame with a SuspensionManager key SuspensionManager.RegisterFrame(shell.AppFrame, "AppFrame"); shell.AppFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { // Something went wrong restoring state. // Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = shell; } // Back to the first(home) page if the app already have pages while (shell.AppFrame.CanGoBack) { shell.AppFrame.GoBack(); } foreach (var item in shell.AppFrame.BackStack) { Debug.WriteLine(item.SourcePageType); } if (shell.AppFrame.Content == null) { shell.AppFrame.Navigate(typeof(BooruViewer.Views.HomePage), e.Arguments); //shell.AppFrame.Navigate(typeof(BooruViewer.Views.TestPage), e.Arguments); } // Handle the launch from a toast var queryString = QueryString.Parse(e.Arguments); string action = null; if (queryString.TryGetValue("action", out action)) { switch (action) { case "viewPost": break; default: break; } } CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; // Ensure the current window is active Window.Current.Activate(); AppSettings.Current.ScreenHeight = DisplayInformation.GetForCurrentView().ScreenHeightInRawPixels; AppSettings.Current.ScreenWidth = DisplayInformation.GetForCurrentView().ScreenWidthInRawPixels; // Update Tags if (TagDataBase.AllTags.Count == 0) { try { await TagDataBase.DownloadLatestTagDBAsync(); } catch (Exception ex) { //new MessageDialog(ex.Message).ShowAsync(); } } BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = "ToastActionTask", //TaskEntryPoint = "RuntimeComponent1.NotificationActionBackgroundTask" }; builder.SetTrigger(new ToastNotificationActionTrigger()); BackgroundTaskRegistration registration = builder.Register(); await new MessageDialog("這是內測版應用,所有內容和功能不代表最終成品。內測者有義務不定期使用QQ或電郵提出反饋和改善建議。請勿在應用商店就內測版內容作出評分或評論。如果無法理解或者無法同意此守則,請卸載本應用。電郵:[email protected]", "使用須知").ShowAsync(); }
private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine("MyBackgroundAudioTask " + sender.TaskId + " Completed..."); deferral.Complete(); }
void task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { //IMPLEMENT SOME CODE TO RUN AFTER YOUR BACKGROUND AGENT COMPLETES. }