本文整理汇总了C#中PeriodicTask类的典型用法代码示例。如果您正苦于以下问题:C# PeriodicTask类的具体用法?C# PeriodicTask怎么用?C# PeriodicTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PeriodicTask类属于命名空间,在下文中一共展示了PeriodicTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PhoneApplicationPage_Loaded
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) {
if(FirstLoad) {
FirstLoad = false;
MainPivot.SelectionChanged += MainPivot_SelectionChanged;
if(NetworkInterface.GetIsNetworkAvailable()) {
if((DataContext as Settings).ComicList.Count == 0) {
try {
(DataContext as Settings).ComicList.Add(await XkcdInterface.GetCurrentComic());
System.Diagnostics.Debug.WriteLine((DataContext as Settings).ComicList.Count);
} catch(WebException) {
ShowNotification("Comic couldn't be loaded", 4000);
}
} else {
GetNewerComics();
}
if(ScheduledActionService.Find(BackgroundTaskName) == null) {
var task = new PeriodicTask(BackgroundTaskName) {
Description = "Gets the number of new comics from xkcd"
};
try {
ScheduledActionService.Add(task);
} catch(InvalidOperationException) { }
}
} else {
ShowNotification(NoNetworkMessage, 4000);
}
}
}
示例2: AddTask
public static void AddTask(string taskName, string description)
{
RemoveTask(taskName);
PeriodicTask task = new PeriodicTask(taskName);
task.Description = description;
ScheduledActionService.Add(task);
}
示例3: Task
public Task()
{
periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
#if DEBUG
if (periodicTask != null)
{
ScheduledActionService.Remove(periodicTaskName);
periodicTask = null;
}
#endif
if (periodicTask == null)
{
periodicTask = new PeriodicTask(periodicTaskName);
periodicTask.Description = "Sparklr notification agent";
try
{
ScheduledActionService.Add(periodicTask);
}
catch (Exception ex)
{
//TODO: Handle errors here (For example if there are too many background tasks already)
}
}
// If debugging is enabled, use LaunchForTest to launch the agent in 15 seconds.
#if DEBUG
ScheduledActionService.LaunchForTest(periodicTaskName, new TimeSpan(0, 0, 15));
#endif
}
示例4: OnNavigatedTo
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Display the default instructions.
agentDetails.Text = defaultTaskDesc;
// Find running periodic task.
tilePeriodicTask = ScheduledActionService.Find(tileTaskName) as PeriodicTask;
// Update the UI based on the running periodic task.
if (toastPeriodicTask != null)
{
// Update the UI to display the currently running toast task info.
PeriodicStackPanel.DataContext = toastPeriodicTask;
TileRadioBtnOption.IsEnabled = false;
startStopButton.Content = stopAgentString;
}
else if (tilePeriodicTask != null)
{
// Update the UI to display the currently running Tile task info.
PeriodicStackPanel.DataContext = tilePeriodicTask;
TileRadioBtnOption.IsChecked = true;
TileRadioBtnOption.IsEnabled = false;
startStopButton.Content = stopAgentString;
agentDetails.Text = tileAgentDetails;
}
else
{
// No running task is running. Select Tile radio button.
TileRadioBtnOption.IsChecked = true;
}
}
示例5: PeriodicTileUpdater
public static void PeriodicTileUpdater()
{
var periodicTask = ScheduledActionService.Find(TaskName) as PeriodicTask;
if ( periodicTask != null )
{
ScheduledActionService.Remove(TaskName);
}
periodicTask = new PeriodicTask(TaskName)
{
Description = "Periodic Task to Update the ApplicationTile"
};
// Place the call to Add in a try block in case the user has disabled agents.
try
{
ScheduledActionService.Add(periodicTask);
// If debugging is enabled, use LaunchForTest to launch the agent in one minute.
//ScheduledActionService.LaunchForTest(TaskName, TimeSpan.FromSeconds(10));
}
catch ( InvalidOperationException ex )
{
Debug.WriteLine(ex.Message);
}
}
示例6: StartTracking
private void StartTracking()
{
string tileTaskId = "PodcastStarterKitPlaybackAudioAgent";
tileTask = ScheduledActionService.Find(tileTaskId) as PeriodicTask;
if (tileTask != null && !tileTask.IsEnabled)
{
MessageBox.Show("Background agent for this application has been disabled by the user.");
return;
}
if (tileTask != null && tileTask.IsEnabled)
{
RemoveAgent(tileTaskId);
}
tileTask = new PeriodicTask(tileTaskId);
tileTask.Description = "New Poscast Finder";
ScheduledActionService.Add(tileTask);
// If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if(DEBUG)
ScheduledActionService.LaunchForTest(tileTaskId, TimeSpan.FromSeconds(60));
#endif
}
示例7: Start
/// <summary>
/// 启动
/// </summary>
public static void Start()
{
if (!AppSetting.IsScheduledAgent)
{
return;
}
if (isAgentOn)
{
return;
}
Stop();
var periodicTask = new PeriodicTask(Params.PeriodicTaskName);
periodicTask.Description = "腾讯微博客户端Altman后台任务,用于帮助用户检查是否有新微博,您可以在应用设置选项中将其关闭或者在手机的后台任务界面停止它。";
try
{
ScheduledActionService.Add(periodicTask);
//ScheduledActionService.LaunchForTest(Common.Params.PeriodicTaskName, TimeSpan.FromSeconds(2));
isAgentOn = true;
}
catch { isAgentOn = false; }
}
示例8: startStopButton_Click
private void startStopButton_Click(object sender, RoutedEventArgs e)
{
// Find a reference to each of the two possibe periodic agents.
tilePeriodicTask = ScheduledActionService.Find(tileTaskName) as PeriodicTask;
// If either periodic agent is running, end it.
// Otherwise, run the periodic agent based on the radio
// button selection.
if ((tilePeriodicTask != null))
{
// If the Tile periodic task is running, end it.
if (tilePeriodicTask != null)
{
RemoveAgent(tileTaskName);
}
}
else
{
// Run the periodic agent based on the radio button selection.
if ((bool)TileRadioBtnOption.IsChecked)
{
StartPeriodicAgent(tileTaskName);
agentDetails.Text = tileAgentDetails;
}
else
{
MessageBoxResult result = MessageBox.Show(startStopButtonMessage);
}
}
}
示例9: Application_Launching
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
// A unique name for the task.
var taskName = "Contoso Cookbook Community Updates";
// If the task exists
var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;
if (oldTask != null)
{
ScheduledActionService.Remove(taskName);
}
// Create the Task
PeriodicTask task = new PeriodicTask(taskName);
// Description is required
task.Description = "This looks for data on recipes shared by your community on Contoso Cookbook";
// Add it to the service to execute
ScheduledActionService.Add(task);
// For debugging
ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromMilliseconds(5000));
}
示例10: Button_Click_1
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string name="PeriodicTask";
PeriodicTask periodicTask = ScheduledActionService.Find(name) as PeriodicTask;
if (periodicTask == null)
{
periodicTask = new PeriodicTask(name);
}
else
{
ScheduledActionService.Remove(name);
periodicTask = new PeriodicTask(name);
}
periodicTask.Description = "描述我们的PeriodicTask后台任务是干什么的";
try
{
ScheduledActionService.Add(periodicTask);
ScheduledActionService.LaunchForTest(name, TimeSpan.FromSeconds(1));
}
catch (InvalidOperationException ioe)
{
}
}
示例11: StartPeriodicAgent
public static void StartPeriodicAgent()
{
// Obtain a reference to the period task, if one exists
var periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
// If the task already exists and background agents are enabled for the
// application, you must remove the task and then add it again to update
// the schedule
if (periodicTask != null)
{
RemoveAgent(periodicTaskName);
}
periodicTask = new PeriodicTask(periodicTaskName);
// The description is required for periodic agents. This is the string that the user
// will see in the background services Settings page on the device.
periodicTask.Description = "换一下大瓷砖背面图片";
// Place the call to Add in a try block in case the user has disabled agents.
try
{
ScheduledActionService.Add(periodicTask);
#if DEBUG
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
GoogleAnalytics.EasyTracker.GetTracker().SendEvent("StartPeriodicAgent", "Result", "success", 1);
}
catch
{
UpdateTileScheduledTaskAgent.ScheduledAgent.ResetTile();
GoogleAnalytics.EasyTracker.GetTracker().SendEvent("StartPeriodicAgent", "Result", "failure", 1);
}
}
示例12: StartPeriodicAgent
public void StartPeriodicAgent()
{
agentsAreEnabled = true;
periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
if (periodicTask != null)
{
RemoveAgent(periodicTaskName);
}
periodicTask = new PeriodicTask(periodicTaskName);
periodicTask.Description = "This demonstrates a periodic task.";
try
{
ScheduledActionService.Add(periodicTask);
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(20));
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains("BNS Error: The action is disabled"))
{
MessageBox.Show("Background agents for this application have been disabled by the user.");
agentsAreEnabled = false;
}
if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
{
// No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
}
}
catch (SchedulerServiceException)
{
// No user action required.
}
}
示例13: Application_Launching
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
const string TASK_NAME = "GPS_TesteTask";
var scheduleTask = ScheduledActionService.Find(TASK_NAME);
if (scheduleTask == null)
{
scheduleTask = new PeriodicTask(TASK_NAME)
{
Description = "Teste de GPS em background"
};
ScheduledActionService.Add(scheduleTask);
}
else if (scheduleTask.IsEnabled)
{
ScheduledActionService.Remove(TASK_NAME);
ScheduledActionService.Add(scheduleTask);
}
#if DEBUG
ScheduledActionService.LaunchForTest(TASK_NAME, TimeSpan.FromSeconds(10));
#endif
// inicializar o GPS uma vez na thread principal
new GeoCoordinateWatcher(GeoPositionAccuracy.High).Start();
}
示例14: EnableLiveTileUpdateTask
private void EnableLiveTileUpdateTask(object sender, RoutedEventArgs e)
{
_periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask;
if (_periodicTask != null)
{
RemoveAgent(PeriodicTaskName);
}
_periodicTask = new PeriodicTask(PeriodicTaskName);
_periodicTask.Description = "JEVGENIDOTNET live tile update task";
try
{
ScheduledActionService.Add(_periodicTask);
#if DEBUG
ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(30));
#endif
btnDisableLiveTileUpdate.IsEnabled = true;
btnEnableLiveTileUpdate.IsEnabled = false;
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains("BNS Error: The action is disabled"))
{
MessageBox.Show("Background agents for this application have been disabled by the user.");
}
}
}
示例15: AddBGTaks
public static void AddBGTaks()
{
PeriodicTask periodicTask = new PeriodicTask("BF3Stats");
periodicTask.Description = "Gets stats in background hourly";
try
{
if (ScheduledActionService.Find(periodicTask.Name) != null)
{
ScheduledActionService.Remove("BF3Stats");
}
ScheduledActionService.Add(periodicTask);
}
catch (InvalidOperationException ex)
{
if (ex.Message.Contains("BNS Error: The action is disabled"))
{
MessageBox.Show("Background agents for this application have been disabled by the user.");
}
if (ex.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
{
// No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
}
}
}