本文整理汇总了C#中Windows.ApplicationModel.Background.BackgroundTaskRegistration类的典型用法代码示例。如果您正苦于以下问题:C# BackgroundTaskRegistration类的具体用法?C# BackgroundTaskRegistration怎么用?C# BackgroundTaskRegistration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BackgroundTaskRegistration类属于Windows.ApplicationModel.Background命名空间,在下文中一共展示了BackgroundTaskRegistration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RegisterTaskAsync
public static IAsyncOperation<BackgroundTaskRegistration> RegisterTaskAsync()
{
return AsyncInfo.Run(async (cancellationToken) =>
{
if (IsTaskRegistered())
return _current;
await BackgroundExecutionManager.RequestAccessAsync();
//http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.background.timetrigger.aspx
IBackgroundTrigger trigger = new TimeTrigger(6*60, false); //6 hours
// Builds the background task.
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
builder.Name = FriendlyName;
builder.TaskEntryPoint = typeof(BackgroundDemoTask).FullName;
builder.SetTrigger(trigger);
SystemCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
builder.AddCondition(condition);
// Registers the background task, and get back a BackgroundTaskRegistration object
// representing the registered task.
_current = builder.Register();
return _current;
});
}
开发者ID:jmservera,项目名称:UniversalBackgroundApp,代码行数:29,代码来源:BackgroundDemoTask.cs
示例2: Task_Completed
void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
if (deferral != null)
{
deferral.Complete();
}
}
开发者ID:poumason,项目名称:DotblogsSampleCode,代码行数:7,代码来源:BackgroundAudioTask.cs
示例3: Register
public static void Register()
{
foreach (var iter in BackgroundTaskRegistration.AllTasks)
{
IBackgroundTaskRegistration mytask = iter.Value;
if (mytask.Name == "ExampleBackgroundTask")
{
mytask.Unregister(true);
break;
}
}
var builder = new BackgroundTaskBuilder();
PushNotificationTrigger trigger = new PushNotificationTrigger();
builder.SetTrigger(trigger);
builder.Name = "ExampleBackgroundTask";
builder.TaskEntryPoint = "Usergrid.Notifications.ExampleBackgroundTask";
ExampleBackgroundTask.task = builder.Register();
task.Progress += task_Progress;
task.Completed += task_Completed;
}
开发者ID:xiongtec,项目名称:usergrid,代码行数:27,代码来源:BackgroundTask.cs
示例4: OnProgress
private async void OnProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
{
// Serialize UI update to the the main UI thread.
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
ShowErrorDialog(CommonData.LastMessage,"Got message");
});
}
开发者ID:caesarjiang,项目名称:BLETestStuffWindows,代码行数:9,代码来源:MainPage.xaml.cs
示例5: OnProgress
void OnProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
if (this.mediaElement.Visibility == Visibility.Collapsed)
{
this.mediaElement.Visibility = Visibility.Visible;
this.mediaElement.Play();
}
this.txtTaskRunning.Text = "Running";
this.progressBar.Value = args.Progress;
});
}
开发者ID:modulexcite,项目名称:TrainingContent,代码行数:14,代码来源:MainPage.xaml.cs
示例6: IsTaskRegistered
public static bool IsTaskRegistered()
{
if (_current == null)
{
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == FriendlyName)
{
// The task is already registered.
_current = (BackgroundTaskRegistration)(cur.Value);
}
}
}
return _current != null;
}
开发者ID:jmservera,项目名称:UniversalBackgroundApp,代码行数:15,代码来源:BackgroundDemoTask.cs
示例7: RegisterLogsUploadTask
public static async Task<BackgroundTaskRegistration> RegisterLogsUploadTask()
{
if (LogsUploadTask != null)
{
return LogsUploadTask;
}
if (Log.IsDebugEnabled)
Log.Debug("Registering LogsUpload background task.");
var accessStatus = await SetUpAccess();
if (accessStatus == BackgroundAccessStatus.Denied) return null;
var result = RegisterBackgroundTask(typeof(LogsUploadTask).FullName,
"LinquaLogsUpload",
new TimeTrigger(LogsUploadTaskIntervalMinutes, false),
new SystemCondition(SystemConditionType.InternetAvailable));
LogsUploadTask = result;
if (Log.IsDebugEnabled)
Log.Debug("Background task registered. TaskId: {0}", result.TaskId);
return result;
}
开发者ID:pglazkov,项目名称:Linqua,代码行数:24,代码来源:BackgroundTaskHelper.cs
示例8: BgTask_Progress
private static void BgTask_Progress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
{
LogMessage("BgTask Progress: " + args.Progress, NotifyType.StatusMessage);
}
开发者ID:jigartailor1984,项目名称:UWPAppSamples,代码行数:4,代码来源:NfcUtils.cs
示例9: OnTaskCompleted
private async void OnTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
{
await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Background task completed", NotifyType.StatusMessage);
});
}
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:7,代码来源:Scenario3_BackgroundDeviceWatcher.xaml.cs
示例10: BgTask_Completed
private static void BgTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
LogMessage("BgTask Completed", NotifyType.StatusMessage);
}
开发者ID:jigartailor1984,项目名称:UWPAppSamples,代码行数:4,代码来源:NfcUtils.cs
示例11: StartSensorBackgroundTaskAsync
/// <summary>
/// Starts the sensor background task.
/// </summary>
/// <param name="deviceId">Device Id for the sensor to be used by the task.</param>
/// <param name="e"></param>
/// <returns>True if the task is started successfully.</returns>
private async Task<bool> StartSensorBackgroundTaskAsync(String deviceId)
{
bool started = false;
// Make sure only 1 task is running.
FindAndCancelExistingBackgroundTask();
// Register the background task.
var backgroundTaskBuilder = new BackgroundTaskBuilder()
{
Name = SampleConstants.Scenario1_TaskName,
TaskEntryPoint = SampleConstants.Scenario1_TaskEntryPoint
};
backgroundTaskBuilder.SetTrigger(_deviceUseTrigger);
_deviceUseBackgroundTaskRegistration = backgroundTaskBuilder.Register();
// Make sure we're notified when the task completes or if there is an update.
_deviceUseBackgroundTaskRegistration.Completed += new BackgroundTaskCompletedEventHandler(OnBackgroundTaskCompleted);
try
{
// Request a DeviceUse task to use the accelerometer.
DeviceTriggerResult deviceTriggerResult = await _deviceUseTrigger.RequestAsync(deviceId);
switch (deviceTriggerResult)
{
case DeviceTriggerResult.Allowed:
rootPage.NotifyUser("Background task started", NotifyType.StatusMessage);
started = true;
break;
case DeviceTriggerResult.LowBattery:
rootPage.NotifyUser("Insufficient battery to run the background task", NotifyType.ErrorMessage);
break;
case DeviceTriggerResult.DeniedBySystem:
// The system can deny a task request if the system-wide DeviceUse task limit is reached.
rootPage.NotifyUser("The system has denied the background task request", NotifyType.ErrorMessage);
break;
default:
rootPage.NotifyUser("Could not start the background task: " + deviceTriggerResult, NotifyType.ErrorMessage);
break;
}
}
catch (InvalidOperationException)
{
// If toggling quickly between 'Disable' and 'Enable', the previous task
// could still be in the process of cleaning up.
rootPage.NotifyUser("A previous background task is still running, please wait for it to exit", NotifyType.ErrorMessage);
FindAndCancelExistingBackgroundTask();
}
return started;
}
开发者ID:SoftwareFactoryUPC,项目名称:ProjectTemplates,代码行数:62,代码来源:Scenario1_DeviceUse.xaml.cs
示例12: OnBackgroundTaskCompleted
/// <summary>
/// This is the background task completion handler.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e)
{
// Dispatch to the UI thread to display the output.
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// An exception may be thrown if an error occurs in the background task.
try
{
e.CheckResult();
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("TaskCancelationReason"))
{
string cancelationReason = (string)ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"];
rootPage.NotifyUser("Background task was stopped, reason: " + cancelationReason, NotifyType.StatusMessage);
}
}
catch (Exception ex)
{
rootPage.NotifyUser("Exception in background task: " + ex.Message, NotifyType.ErrorMessage);
}
_refreshTimer.Stop();
});
// Unregister the background task and let the remaining task finish until completion.
if (null != _deviceUseBackgroundTaskRegistration)
{
_deviceUseBackgroundTaskRegistration.Unregister(false);
_deviceUseBackgroundTaskRegistration = null;
}
}
开发者ID:SoftwareFactoryUPC,项目名称:ProjectTemplates,代码行数:35,代码来源:Scenario1_DeviceUse.xaml.cs
示例13: Taskcompleted
private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
BackgroundMediaPlayer.Shutdown();
_deferral.Complete();
}
开发者ID:se-bastiaan,项目名称:TVNL-WindowsPhone,代码行数:5,代码来源:BackgroundAudioTask.cs
示例14: RegTask_Completed
private async void RegTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
string json = await readStringFromLocalFile("parking.json");
ParkingResult[] result = JsonConvert.DeserializeObject<ParkingResult[]>(json);
foreach(var parking in result)
{
if (parking.parkingStatus == null)
continue;
points.Add(new PointOfInterest()
{
DisplayName = parking.name,
FreePlaces = parking.parkingStatus.availableCapacity,
Location = new Geopoint(new BasicGeoposition()
{
Latitude = parking.latitude,
Longitude = parking.longitude
}),
ParkingResult = parking
});
}
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, RefreshUI);
}
开发者ID:drummendejef,项目名称:App-Dev-For-Windows_lessen,代码行数:25,代码来源:MainPage.xaml.cs
示例15: OnBackgroundTaskCompleted
/// <summary>
/// Handle background task completion.
/// </summary>
/// <param name="task">The task that is reporting completion.</param>
/// <param name="e">Arguments of the completion report.</param>
private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs eventArgs)
{
// We get the advertisement(s) processed by the background task
if (ApplicationData.Current.LocalSettings.Values.Keys.Contains(taskName))
{
string backgroundMessage = (string) ApplicationData.Current.LocalSettings.Values[taskName];
// Serialize UI update to the main UI thread
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// Display these information on the list
ReceivedAdvertisementListBox.Items.Add(backgroundMessage);
});
}
}
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:19,代码来源:Scenario3_BackgroundWatcher.xaml.cs
示例16: OnBackgroundTaskCompleted
private void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
args.CheckResult(); // TODO: What kind of errors does this report?
Debug.WriteLine(sender); // BackgroundTaskRegistration
string instanceIdString = args.InstanceId.ToString();
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(instanceIdString))
{
// This task didn't schedule a download.
return;
}
Guid transferGuid = (Guid)ApplicationData.Current.LocalSettings.Values[instanceIdString];
Debug.WriteLine("Background task completed! Last download was {0}", transferGuid);
}
开发者ID:kiewic,项目名称:Projects,代码行数:15,代码来源:App.xaml.cs
示例17: OnSyncWithDeviceProgress
/// <summary>
/// Updates the UI with the progress of the sync
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private async void OnSyncWithDeviceProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
{
await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
new DispatchedHandler(() =>
{
SyncProgressBar.Value = args.Progress;
}));
}
开发者ID:mbin,项目名称:Win81App,代码行数:13,代码来源:Scenario7_SyncDevice.xaml.cs
示例18: Completed
private void Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
defferal.Complete();
}
开发者ID:Solocast,项目名称:solocast-clients,代码行数:4,代码来源:AudioBackgroundTask.cs
示例19: Taskcompleted
/// <summary>
/// Indicate that the background task is completed.
/// </summary>
private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
logger.LogMessage($"Background Audio Task {sender.TaskId} Completed...");
Dispose();
}
开发者ID:starkole,项目名称:AsotListener,代码行数:8,代码来源:AudioPlayerTask.cs
示例20: ScenarioDisable
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
_refreshTimer.Stop();
if (null != _deviceUseBackgroundTaskRegistration)
{
// Cancel and unregister the background task from the current app session.
_deviceUseBackgroundTaskRegistration.Unregister(true);
_deviceUseBackgroundTaskRegistration = null;
}
else
{
// Cancel and unregister the background task from the previous app session.
FindAndCancelExistingBackgroundTask();
}
rootPage.NotifyUser("Background task was canceled", NotifyType.StatusMessage);
}
开发者ID:SoftwareFactoryUPC,项目名称:ProjectTemplates,代码行数:28,代码来源:Scenario1_DeviceUse.xaml.cs
注:本文中的Windows.ApplicationModel.Background.BackgroundTaskRegistration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论