当前位置: 首页>>代码示例>>C#>>正文


C# BackgroundTaskDeferral.Complete方法代码示例

本文整理汇总了C#中Windows.ApplicationModel.Background.BackgroundTaskDeferral.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundTaskDeferral.Complete方法的具体用法?C# BackgroundTaskDeferral.Complete怎么用?C# BackgroundTaskDeferral.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.ApplicationModel.Background.BackgroundTaskDeferral的用法示例。


在下文中一共展示了BackgroundTaskDeferral.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails == null)
            {
                serviceDeferral.Complete();
                return;
            }

            try
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                //Find the command name witch should match the VCD
                if (voiceCommand.CommandName == "buildit_help")
                {
                    var props = voiceCommand.Properties;
                    await CortanaHelpList();
                }
                await Task.Delay(1000);
                await ShowProgressScreen();
            }
            catch
            {
                Debug.WriteLine("Unable to process voice command");
            }
            serviceDeferral.Complete();
        }
开发者ID:builttoroam,项目名称:BuildIt,代码行数:35,代码来源:BaseCortanaBackgroundTask.cs

示例2: Run

        public async void Run( IBackgroundTaskInstance taskInstance )
        {
            Deferral = taskInstance.GetDeferral();

            XParameter[] Params = SavedChannels.Parameters( "channel" );

            if ( Params.Length == 0 )
            {
                Deferral.Complete();
                return;
            }

            // Associate a cancellation handler with the background task.
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler( OnCanceled );

            foreach ( XParameter Param in Params )
            {
                CurrentTask = new XParameter( DateTime.Now.ToFileTime() + "" );
                CurrentTask.SetValue( new XKey[] {
                    new XKey( "name", taskInstance.Task.Name )
                    , new XKey( "start", true )
                    , new XKey( "end", false )
                } );

                PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                if ( channel.Uri != Param.GetValue( "uri" ) )
                {
                    await RenewChannel( Param.GetValue( "provider" ), Param.Id, Uri.EscapeDataString( channel.Uri ) );
                }

            }

            Deferral.Complete();
        }
开发者ID:tgckpg,项目名称:term-notify,代码行数:35,代码来源:ChannelRenewal.cs

示例3: Run

 /// <summary>
 /// Entry point for the background task.
 /// </summary>
 public async void Run(IBackgroundTaskInstance taskInstance)
 {
     var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
     if (null != triggerDetails && triggerDetails.Name == "LightControllerVoiceCommandService")
     {
         _deferral = taskInstance.GetDeferral();
         taskInstance.Canceled += (s, e) => _deferral.Complete();
         if (true != await InitializeAsync(triggerDetails))
         {
             return;
         }
         // These command phrases are coded in the VoiceCommands.xml file.
         switch (_voiceCommand.CommandName)
         {
             case "changeLightsState": await ChangeLightStateAsync(); break;
             case "changeLightsColor": await SelectColorAsync(); break;
             case "changeLightStateByName": await ChangeSpecificLightStateAsync(); break;
             default: await _voiceServiceConnection.RequestAppLaunchAsync(
                 CreateCortanaResponse("Launching HueLightController")); break;
         }
         // keep alive for 1 second to ensure all HTTP requests sent.
         await Task.Delay(1000);
         _deferral.Complete();
     }
 }
开发者ID:Microsoft,项目名称:Windows-appsample-huelightcontroller,代码行数:28,代码来源:Cortana.cs

示例4: Run

        /// <summary>
        /// The entry point of a background task.
        /// </summary>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            backgroundTaskInstance = taskInstance;
            var details = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;
            if (details != null)
            {
                _deferral = backgroundTaskInstance.GetDeferral();
                taskInstance.Canceled += (s, e) => _deferral.Complete();

                var localStorage = ApplicationData.Current.LocalSettings.Values;
                _bridge = new Bridge(localStorage["bridgeIp"].ToString(), localStorage["userId"].ToString()); 
                try
                {
                    _lights = await _bridge.GetLightsAsync();
                }
                catch (Exception)
                {
                    _deferral.Complete();
                    return; 
                }
                foreach(var item in details.Advertisements)
                {
                    Debug.WriteLine(item.RawSignalStrengthInDBm);
                }

                // -127 is a BTLE magic number that indicates out of range. If we hit this, 
                // turn off the lights. Send the command regardless if they are on/off
                // just to be safe, since it will only be sent once.
                if (details.Advertisements.Any(x => x.RawSignalStrengthInDBm == -127))
                {
                    foreach (Light light in _lights)
                    {
                        light.State.On = false;
                        await Task.Delay(250);
                    }
                }
                // If there is no magic number, we are in range. Toggle any lights reporting
                // as off to on. Do not spam the command to lights arleady on. 
                else
                {
                    foreach (Light light in _lights.Where(x => !x.State.On))
                    {
                        light.State.On = true;
                        await Task.Delay(250);
                    }
                }
                // Wait 1 second before exiting to ensure all HTTP requests have sent.
                await Task.Delay(1000);
                _deferral.Complete();
            }
        }
开发者ID:Microsoft,项目名称:Windows-appsample-huelightcontroller,代码行数:54,代码来源:Bluetooth.cs

示例5: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("WE are @ Background");
            _deferral = taskInstance.GetDeferral();
            _taskInstance = taskInstance;
            _taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

            GattCharacteristicNotificationTriggerDetails details = (GattCharacteristicNotificationTriggerDetails)taskInstance.TriggerDetails;

            //get the characteristics data and get heartbeat value out from it
            byte[] ReceivedData = new byte[details.Value.Length];
            DataReader.FromBuffer(details.Value).ReadBytes(ReceivedData);

            HeartbeatMeasurement tmpMeasurement = HeartbeatMeasurement.GetHeartbeatMeasurementFromData(ReceivedData);

            System.Diagnostics.Debug.WriteLine("Background heartbeast values: " + tmpMeasurement.HeartbeatValue);

            // send heartbeat values via progress callback
            _taskInstance.Progress = tmpMeasurement.HeartbeatValue;

            //update the value to the Tile
            LiveTile.UpdateSecondaryTile("" + tmpMeasurement.HeartbeatValue);
            
            //Check if we are within the limits, and alert by starting the app if we are not
            alertType alert = await checkHeartbeatLevels(tmpMeasurement.HeartbeatValue);

            _deferral.Complete();
        }
开发者ID:caesarjiang,项目名称:BLETestStuffWindows,代码行数:28,代码来源:HeartbeatMonitorBackgroundTask.cs

示例6: Run

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            try {
                var triggerDetail = (AppServiceTriggerDetails) taskInstance.TriggerDetails;
                _deferral = taskInstance.GetDeferral();

                Hub.Instance.ForegroundConnection = triggerDetail.AppServiceConnection;
                Hub.Instance.ForegroundTask = this;

                taskInstance.Canceled += (s, e) => Close();
                triggerDetail.AppServiceConnection.ServiceClosed += (s, e) => Close();
            }
            catch (System.Exception e)
            {
                if (Hub.Instance.IsAppInsightsEnabled)
                {
                    Hub.Instance.RTCStatsManager.TrackException(e);
                }
                if (_deferral != null)
                {
                    _deferral.Complete();
                }
                throw e;
            }
        }
开发者ID:openpeer,项目名称:ChatterBox,代码行数:25,代码来源:ForegroundAppServiceTask.cs

示例7: Run

        //
        // The Run method is the entry point of a background task.
        //
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
            if (details != null)
            {
                string arguments = details.Argument;
                var userInput = details.UserInput;
            }
            Debug.WriteLine("Background " + taskInstance.Task.Name + " Starting...");
            //
            // Query BackgroundWorkCost
            // Guidance: If BackgroundWorkCost is high, then perform only the minimum amount
            // of work in the background task and return immediately.
            //
            var cost = BackgroundWorkCost.CurrentBackgroundWorkCost;
            var settings = ApplicationData.Current.LocalSettings;
            settings.Values["BackgroundWorkCost"] = cost.ToString();
            //
            // Associate a cancellation handler with the background task.
            //
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

            //
            // Get the deferral object from the task instance, and take a reference to the taskInstance;
            //
            _deferral = taskInstance.GetDeferral();
            _taskInstance = taskInstance;
            _deferral.Complete();

            // _periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(PeriodicTimerCallback), TimeSpan.FromSeconds(1));
        }
开发者ID:JamborYao,项目名称:UwpStart,代码行数:34,代码来源:NotificationBackground.cs

示例8: Run

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                if (Hub.Instance.VoipTaskInstance != null)
                {
                    Debug.WriteLine("VoipTask already started.");
                    return;
                }

                _deferral = taskInstance.GetDeferral();
                Hub.Instance.VoipTaskInstance = this;
                Debug.WriteLine($"{DateTime.Now} VoipTask started.");
                taskInstance.Canceled += (s, e) => CloseVoipTask();
            }
            catch (Exception e)
            {
                if (Hub.Instance.IsAppInsightsEnabled)
                {
                    Hub.Instance.RTCStatsManager.TrackException(e);
                }
                if (_deferral != null)
                {
                    _deferral.Complete();
                }
                throw e;
            }
        }
开发者ID:hungdluit,项目名称:ChatterBox,代码行数:28,代码来源:VoipTask.cs

示例9: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();
            Services.IoC.Register();
            var container = Container.Instance;
            logger = container.Resolve<ILogger>();

            taskInstance.Task.Completed += onTaskCompleted;
            taskInstance.Canceled += onTaskCanceled;
            logger.LogMessage("BackgroundUpdater: Task initialized.", LoggingLevel.Information);

            var episodeListManager = container.Resolve<IEpisodeListManager>();
            await episodeListManager.Initialization;
            var oldEpisodeList = EpisodeList.Instance.ToList();
            await episodeListManager.LoadEpisodeListFromServerAsync();
            var diff = EpisodeList.Instance.Except(oldEpisodeList).ToList();
            if (diff.Any())
            {
                var downloadManager = container.Resolve<IDownloadManager>();
                await downloadManager.Initialization;
                foreach (var episode in diff)
                {
                    await downloadManager.DownloadEpisode(episode);
                }
            }

            deferral.Complete();
        }
开发者ID:starkole,项目名称:AsotListener,代码行数:28,代码来源:BackgroundUpdaterTask.cs

示例10: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // Create the deferral by requesting it from the task instance
            serviceDeferral = taskInstance.GetDeferral();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name.Equals("IMCommandVoice"))
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                // Perform the appropriate command depending on the operation defined in VCD
                switch (voiceCommand.CommandName)
                {
                    case "oldback":
                        VoiceCommandUserMessage userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "The current temperature is 23 degrees";
                        userMessage.SpokenMessage = "The current temperature is 23 degrees";

                        VoiceCommandResponse response = VoiceCommandResponse.CreateResponse(userMessage, null);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                        break;

                    default:
                        break;
                }
            }

            // Once the asynchronous method(s) are done, close the deferral
            serviceDeferral.Complete();
        }
开发者ID:lcarli,项目名称:IntelliMarketing,代码行数:33,代码来源:IMCommandVoice.cs

示例11: Run

    public void Run(IBackgroundTaskInstance taskInstance)
    {
      Debug.WriteLine("Background " + taskInstance.Task.Name + " Starting...");

      taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

      _deferral = taskInstance.GetDeferral();

      ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

      var settings = Windows.Storage.ApplicationData.Current.LocalSettings;
      var status = "";
      switch (InternetConnectionProfile.GetNetworkConnectivityLevel())
      {
        case NetworkConnectivityLevel.None:
          status = "無連線";
          break;
        case NetworkConnectivityLevel.LocalAccess:
          status = "本地連線";
          break;
        case NetworkConnectivityLevel.ConstrainedInternetAccess:
          status = "受限的連線";
          break;
        case NetworkConnectivityLevel.InternetAccess:
          status = "網際網路連線";
          break;
      }
      settings.Values["NetworkStatus"] = status;

      _deferral.Complete();
    }
开发者ID:liqinghuang,项目名称:UWPBootCamp,代码行数:31,代码来源:NetworkTask.cs

示例12: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            await WhirlMonData.WhirlPoolAPIClient.GetDataAsync();

            _deferral.Complete();
        }
开发者ID:Blackpaw,项目名称:WhirlMon,代码行数:8,代码来源:MainBackground.cs

示例13: Run

        /// <summary>
        /// The entry point of a background task.
        /// </summary>
        /// <param name="taskInstance">The current background task instance.</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // Get the deferral to prevent the task from closing prematurely
            deferral = taskInstance.GetDeferral();

            // Setup our onCanceled callback and progress
            this.taskInstance = taskInstance;
            this.taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
            this.taskInstance.Progress = 0;

            // Store a setting so that the app knows that the task is running. 
            ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = true;

            periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(PeriodicTimerCallback), TimeSpan.FromSeconds(1));

            try
            {
                RfcommConnectionTriggerDetails details = (RfcommConnectionTriggerDetails)taskInstance.TriggerDetails;
                if (details != null)
                {
                    socket = details.Socket;
                    remoteDevice = details.RemoteDevice;
                    ApplicationData.Current.LocalSettings.Values["RemoteDeviceName"] = remoteDevice.Name;

                    writer = new DataWriter(socket.OutputStream);
                    reader = new DataReader(socket.InputStream);
                }
                else
                {
                    ApplicationData.Current.LocalSettings.Values["BackgroundTaskStatus"] = "Trigger details returned null";
                    deferral.Complete();
                }

                var result = await ReceiveDataAsync();
            }
            catch (Exception ex)
            {
                reader = null;
                writer = null;
                socket = null;
                deferral.Complete();

                Debug.WriteLine("Exception occurred while initializing the connection, hr = " + ex.HResult.ToString("X"));
            }
        }
开发者ID:jigartailor1984,项目名称:UWPAppSamples,代码行数:49,代码来源:RfcommServerTask.cs

示例14: Run

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            RunBot().Wait();

            _deferral.Complete();

        }
开发者ID:MrRoundRobin,项目名称:telegram.bot.examples,代码行数:9,代码来源:StartupTask.cs

示例15: OnRun

        /// <summary>
        /// ライブタイル更新起動
        /// </summary>
        /// <param name="taskInstance"></param>
        protected async override void OnRun(IBackgroundTaskInstance taskInstance)
        {
            m_deferral = taskInstance.GetDeferral();

            //更新処理開始
            await updateTile();

            m_deferral.Complete();
        }
开发者ID:mryp,项目名称:radame,代码行数:13,代码来源:LiveTileUpdateTask.cs


注:本文中的Windows.ApplicationModel.Background.BackgroundTaskDeferral.Complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。