コード例 #1
0
 void task_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
 {
 }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: Bgt.cs プロジェクト: alexpisquared/MediaPlay
 void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine("Bgt " + sender.TaskId + " Completed...");
     deferral.Complete();
 }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: PHone5y/bilibili
 private void A_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine("---------Completed!---------");
 }
コード例 #5
0
        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;
        }
コード例 #6
0
 private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) => _deferal.Complete();
コード例 #7
0
 private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     BackgroundMediaPlayer.Shutdown();
     _deferral.Complete();
 }
コード例 #8
0
 private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Task_Completed)}");
 }
コード例 #9
0
 private void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     library.IsPlaying = false;
     //MobileDebug.Service.WriteEvent("TaskCompleted");
     Cancel();
 }
コード例 #10
0
ファイル: App.xaml.cs プロジェクト: laplamgor/PRPR
        /// <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();
        }
コード例 #11
0
 private void Task_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
 {
     Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Task_Progress)} - {args.InstanceId} : {args.Progress}");
 }
コード例 #12
0
        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();
            });
        }
コード例 #13
0
 private void OnRegisteredTaskProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args) => OnTaskProgress((int)args.Progress);
コード例 #14
0
 private void OnRegisteredTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) => OnTaskCompleted();
コード例 #15
0
 private static void BgTask_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
 {
     LogMessage("BgTask Progress: " + args.Progress, NotifyType.StatusMessage);
 }
コード例 #16
0
 private void Btr_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     isUpdateCompleted = true;
 }
コード例 #17
0
 private static void BgTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     LogMessage("BgTask Completed", NotifyType.StatusMessage);
 }
コード例 #18
0
 //--------------------------------------------------------Events:---------------------------------------------------------------------\\
 #region --Events--
 private static void OnBackgroundTaskRegistrationCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     sender.Completed -= OnBackgroundTaskRegistrationCompleted;
     Logger.Info("Registered " + sender.Name + " background task.");
 }
コード例 #19
0
 /// <summary>
 /// Indicate that the background task is completed.
 /// </summary>
 void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine($"MyBackgroundAudioTask {sender.TaskId} Completed...");
     deferral.Complete();
 }
コード例 #20
0
 private void TaskOnProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
 {
     Debug.WriteLine($"Background {sender.Name} TaskOnProgress.");
 }
コード例 #21
0
 private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     TaskCompleted?.Invoke(sender, args);
 }
コード例 #22
0
 private void TaskOnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine($"Background {sender.Name} TaskOnCompleted.");
 }
コード例 #23
0
ファイル: MainPage.xaml.cs プロジェクト: PHone5y/bilibili
 private void A_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
 {
     Debug.WriteLine("---------Processing...---------");
 }
コード例 #24
0
 /// <summary>
 /// 指示后台任务结束
 /// </summary>
 private void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     DebugWrite("BackgroundAudioTask " + sender.TaskId + " Completed...", "BackgroundPlayer");
     deferral.Complete();
 }
コード例 #25
0
 /// <summary>
 /// Indicate that the background task is completed.
 /// </summary>
 void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     deferral.Complete();
 }
コード例 #26
0
 private void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
 }
コード例 #27
0
 async void task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine(sender.Name);
 }
コード例 #28
0
ファイル: App.xaml.cs プロジェクト: gareiz/PRPR
        /// <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();
        }
コード例 #29
0
 private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Debug.WriteLine("MyBackgroundAudioTask " + sender.TaskId + " Completed...");
     deferral.Complete();
 }
コード例 #30
0
 void task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     //IMPLEMENT SOME CODE TO RUN AFTER YOUR BACKGROUND AGENT COMPLETES.
 }